Welcome to Zuora Product Documentation

Explore our rich library of product information

Formula function use cases

Common use cases and code samples of formula function.

Calculate tax due

The following code sample updates the SalesTax__c field with the value of multiplying the purchase amount in the PurchaseAmount__c field by the tax rate in the TaxRate__c field.

((default__vehicle) => {
    const purchaseAmount = default__vehicle.PurchaseAmount__c;
    const taxRate = default__vehicle.TaxRate__c;
    const salesTax = purchaseAmount * taxRate;
    return {
        success: true,
        message: "The sales tax is updated.",
        data: {
            SalesTax__c: salesTax
        }
    };
})(default__vehicle);

Calculate total production cost

The following code sample updates the Total_Production_Cost__c field with the sum of values in the Materials_Cost__c, Labor_Cost__c, and Overhead_Cost__c fields.

((default__manufacturing) => {
    const materialsCost = default__manufacturing.Materials_Cost__c,
    const laborCost = default__manufacturing.Labor_Cost__c,
    const overheadCost = default__manufacturing.Overhead_Cost__c,
    const totalProductionCost = materialsCost + laborCost + overheadCost;
    return {
        success: true,
        message: "The total production cost is updated",
        data: {
            Total_Production_Cost__c: totalProductionCost
        }
    };
})(default__manufacturing);

The following code sample sets the AdditionalInfo__c field on the Subscription Rate Plan Charge object using the value from the CustomField__c field on the related Product Rate Plan Charge object.

((rateplancharge) => {
    let productRatePlanCharge = rateplancharge.ProductRatePlanCharge;
    let result = { success: true };
    if (productRatePlanCharge.CustomField__c !== null) {
        result = {
            ...result,
            data: {
                AdditionalInfo__c: productRatePlanCharge.CustomField__c
            }
        };
    }
    return result;
})(rateplancharge);

This use case demonstrates how to access fields on joined objects related to a function's base object. For more information about object relationships, see Zuora business object model.

It is recommended to use Zuroa Workflow for use cases that require referencing objects not related to the base object or traversing multiple objects, such as multi-step operations.