var totalPrice = payload.order.total_price;

function applyDiscount(totalPrice) {
  var discount = totalPrice * 0.15;
  var discountedPrice = totalPrice - discount;
  return discountedPrice;
}

var appliedDiscount = applyDiscount(totalPrice);

payload.appliedDiscount;

In Reportana’s advanced automations and campaigns, you have access to the global variable payload, which can be used to access data within arrays and objects. This variable allows you, for example, to retrieve specific information from an array of orders and manipulate that data as needed. Additionally, the payload variable can be used within the Execute JavaScript block, providing even more customization options for the scripts executed through this feature. See the example below:

var totalPrice = payload.order.total_price

In this example, we store the total order value in the variable totalPrice by accessing the payload.order object and its total_price attribute (the total order amount). This allows us to perform, for instance, a calculation to automatically apply a discount coupon to the total order value:

var totalPrice = payload.order.total_price;

function applyDiscount(totalPrice) {
  var discount = totalPrice * 0.15;
  var discountedPrice = totalPrice - discount;
  return discountedPrice;
}

var appliedDiscount = applyDiscount(totalPrice);

payload.appliedDiscount;