Manage functions
This article describes how to create, update, delete, or test functions.
Prerequisite
To manage functions, you must have a basic understanding of JavaScript functions. For more information, see JavaScript and Functions in MDN Web Docs.
Create a function from scratch
To create a function from scratch, perform the following steps:
- Navigate to Platform > Custom Logic in the left navigation menu.
- Click Create Logic and then click Create from Blank.
- In the displayed Create New Logic dialog, complete the following information:
- Type: Select Function.
- Name: Enter the function name. The name must be unique across all custom logics.
- Object: Select the related object.
- Description: Enter the function description.
- Select Event Trigger: Select either or both event triggers.
- Upon Object Record Create: Zuora will execute the function when an object record is created.
- Upon Object Record Update: Zuora will execute the function when an object record is updated.
- Enter Script: Enter the JavaScript code of the function body.
Note that Zuora provides the other parts of the function except the function body by default. See the following snippet as an example:((account) => { //Available by default … //Function body. Enter this part in the field })(account) //Available by default
It can be a validation or formula function. For more information, see Function types, Function format, and Use cases and code samples.
- Optional: Test the function. For more information, see Test a function.
- Click Save And Activate or Save As Draft.
Active functions are effective immediately, whereas draft functions are not.
Note that only one active function is allowed for each object.
Create a function from templates
To create a function from a template, perform the following steps:
- Navigate to Platform > Custom Logic in the left navigation menu.
- Click Create Logic and then click Create from Templates.
- In the “Choose a template from library” dialog, select the template on which the function is based:
- Click Functions in the Categories section.
- Select an object from the dropdown list.
- Select a template in the Functions section.
Available templates vary depending on the object you selected in step b.
- Optional: In the Create New Logic dialog, update the prepopulated information as needed:
- Name
- Description
- JavaScript code
- Select either or both event triggers from the Select Event Trigger list:
- Upon Object Record Create: Zuora will execute the function when an object record is created.
- Upon Object Record Update: Zuora will execute the function when an object record is updated.
- Optional: Test the function. For more information, see Test a function.
- Click Save And Activate or Save As Draft.
Active functions are effective immediately, whereas draft functions are not.
Note that only one active function is allowed for each object.
Update a function
To update a function, perform the following steps:
- Navigate to Platform > Custom Logic in the left navigation menu.
- Locate the function you want to edit and then click the function name.
- Update the following information:
- Description
- Event trigger
- JavaScript code
- Optional: Test the function. For more information, see Test a function.
- Click Save And Activate or Save As Draft.
Note that Save As Draft is available only if this is a draft function.
Activate a function
When a function is in the Draft or Inactive status, you can activate it by performing the following steps:
- Navigate to Platform > Custom Logic in the left navigation menu.
- Locate the function you want to activate and then click the function name.
- Click Save And Activate.
You can have at most one active function for each object.
Delete a function
To delete a function, perform the following steps:
- Navigate to Platform > Custom Logic in the left navigation menu.
- Locate the function you want to delete.
- Click the more options icon and then click Delete. A confirmation dialog is displayed.
- Click Delete.
Test a function
To ensure the return value of a function meets your expectations, it is a good practice to test a function before activating it.
You can test a function during the creation or update.
To test a function, perform the following steps:
- Click Test when creating or updating a function. The Input and Output fields are displayed.
All custom fields of the current object are pre-populated in the Input field with thenull
value. - Optional: Edit field names in the Input field.
You can also add standard fields if the context object is a standard object. - Specify field values in the Input field for testing.
After changes to the Input field are detected, Zuora calls this function with the data in the Input field as input value and displays the return value in the Output field.
- If the return value is not as you expected, revise the JavaScript code in the Enter Script field and repeat steps 2 and 3.