Example 1: Creating a calculated value in a business object field.
In this example, two business object fields (Order Item Quantity and Order Item Price) are multiplied to produce the value for Order Item Total. The value is passed to all action object fields that are contained in fired event rules and that map to the business object field. The fields are in purple, meaning that the fields have been verified as existing assets and are treated as a scalar.
For information about the colors displayed in the JavaScript expression, see Colors displayed in JavaScript expressions.
Order Item Price * Order Item Quantity
Example 2: Using a local variable and an if…else condition.
In this example, a local variable is assigned an initial value of 0. An if...else statement evaluates a business object field (CountPurchases). If that field has a value greater than 0, then the value of result is set to a percentage; if not, then the value of result remains 0.
var result = 0;
if (CountPurchases > 0)
{result = CountPurchasesWithPromoCode /
CountPurchases * 100
}
result;
Example 3: Performing a transformation in an action object field.
In this example, the split method of the JavaScript string object is used to split the Full Name business object field into an array (by using a comma as the value to split on), and the second value in the array is assigned to the variable a. This value is assigned to the FirstName action object field and passed to the touchpoint system when an event rule group that contains the action fires.The business object name (Customer) is used to qualify the business object field name (Full Name).
var a = (Full Name).split(",");
a[1]
Example 4: Performing a function.
In this example, a function called OrderTotal(priceArray,quantityArray) is defined as a function local to the Order Total business object field. The function loops through the array of Order Item business object instances and uses the local variable sum to add the product of two fields to itself and then returns the total.
function OrderTotal(priceArray,quantityArray)
{
var sum=0;for (var i=0; i <priceArray.length; i++) sum = sum + (priceArray[i]*quantityArray[i]);
return sum;
}
OrderTotal(Order Item Price, Order Item Quantity)