Skip to main content

Manage functions

Zuora

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:

  1. Navigate to Platform > Custom Logic in the left navigation menu.
  2. Click Create Logic and then click Create from Blank.
  3. 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.
  4. Optional: Test the function. For more information, see Test a function.
  5. 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:

  1. Navigate to Platform > Custom Logic in the left navigation menu.
  2. Click Create Logic and then click Create from Templates.
  3. In the “Choose a template from library” dialog, select the template on which the function is based:
    1. Click Functions in the Categories section.
    2. Select an object from the dropdown list.
    3. Select a template in the Functions section.
      Available templates vary depending on the object you selected in step b.
  4. Optional: In the Create New Logic dialog, update the prepopulated information as needed:
    • Name
    • Description
    • JavaScript code
  5. 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.
  6. Optional: Test the function. For more information, see Test a function.
  7. 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:

  1. Navigate to Platform > Custom Logic in the left navigation menu.
  2. Locate the function you want to edit and then click the function name.
  3. Update the following information:
    • Description
    • Event trigger
    • JavaScript code
  4. Optional: Test the function. For more information, see Test a function.
  5. 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:

  1. Navigate to Platform > Custom Logic in the left navigation menu.
  2. Locate the function you want to activate and then click the function name.
  3. 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:

  1. Navigate to Platform > Custom Logic in the left navigation menu.
  2. Locate the function you want to delete.
  3. Click the more options icon icon-more-options-2.png and then click Delete. A confirmation dialog is displayed.
  4. 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:

  1. Click Test when creating or updating a function. The Input and Output fields are displayed.
    test_function.png
    All custom fields of the current object are pre-populated in the Input field with the null value.
  2. Optional: Edit field names in the Input field.
    You can also add standard fields if the context object is a standard object.
  3. 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.
    test_function_failure.png
    test_function_success.png
  4. If the return value is not as you expected, revise the JavaScript code in the Enter Script field and repeat steps 2 and 3.