Skip to content
Release: Australia · Updated: 2026-03-12 · Official documentation · View source

Create a custom action to generate an array of objects from a list of records

Generate an array of objects from a list of User records. Learn how to use a Script step to iterate through a list of records.

Before you begin

Role required: admin of flow_designer

About this task

Use this example to see demonstrations of these operations and steps.

  • Create an action input for a Department record.
  • Look up a maximum of three User records for the Department action input.
  • Configure a Script step to process a list of User records.
  • Create a script input variable containing the list of User records.
  • Write script that creates an empty contacts array.
  • Write script that iterates through the list of User records.
  • Write script that creates a contact object and maps User record field values to the contact object.
  • Write script that populates the contacts array with the current contact object.
  • Create script output variables for the contacts array and child contact object.
  • Save the contact object as a template.
  • Output the generated contacts array of objects as a data pill.
  • Test the action with a sample department.

Procedure

  1. Create an application to store your work.

    You can use App Engine Studio to plan, create, and deploy applications. For more information about building a custom application, see .

    For example, create an application called My Application.

  2. Navigate to All > Process Automation > Workflow Studio.

  3. On the homepage, select Actions.

  4. Select New > Action

    The system displays the Action Properties dialog.

  5. Enter these sample values.

    FieldValue
    NameCreate Contacts Array Of Objects
    ApplicationGlobal
    Accessible FromAll application scopes

    Note: If you created an application to store and deploy your custom action, use that application instead of global.

  6. Select Build action.

    The system displays the Workflow Studio interface.

  7. From the Action Outline, select Inputs > Create Input

    The system displays a new action input.

  8. Configure the action input with these values.

Image omitted: array-objects-config-inputs.png
Create an action input that stores a department record.
|Field|Value|
|-----|-----|
|Label|Department|
|Type|Reference.Department \[Reference.cmn\_department\]|
|Mandatory|True|
  1. From the Action Outline, select Add a new step.

    The system displays a list of available steps.

  2. Select Look Up Records

  3. Configure the step with these values.

Image omitted: array-objects-config-look-up-records-step.png
Configure the Look Up Records step condition to use the department input variable.
FieldValue
TableUser \[sys\_user\]
Conditions[Department][is][action->Department]Note: Select the Department data pill from the Input Variables.
Order byName
Sort Typea to z
Max Results3
**Note:** This example limits the **Max Results** setting to three records just for demonstration purposes.
  1. From the Action Outline, select Add a new step.

    The system displays a list of available steps.

  2. Select Script.

  3. From the Input Variables section, select Create Variable.

  4. Configure the input variable with these values.

Image omitted: array-objects-config-script-step-variable.png
Configure the Script step input variable to use the User records data pill from the Look Up Records step.
FieldValue
NameuserRecords
Value[step->Look Up Records step->User Records]Note: Select the User records data pill from the Look Up Records step.
**Note:** You can select the **User records** data pill from the data panel or from the Data Pill Picker button.
  1. For Script, enter the following text.

    (function execute(inputs, outputs) {
      //Create an empty array
      var contactsArray = [];
      var i = 0;
      //Iterate through the list of User records
      while(inputs.userRecords.next()) {
        //Create an empty object for each iteration
        var contactObject = {};
        //Query User records to assign object values
        contactObject.first_name = inputs.userRecords.getValue('first_name');
        contactObject.last_name = inputs.userRecords.getValue('last_name');
        contactObject.email_address = inputs.userRecords.getValue('email');
        //Add current object to array
        contactsArray[i] = contactObject;
        i += 1;
      }
      outputs.contacts = contactsArray;
    })(inputs, outputs);
    
  2. From Output Variables, select Create Variable.

  3. Configure the output variable with these values.

Image omitted: array-objects-config-script-step-output-variables.png
Create an array of objects called contacts. Within the array create an object called contact. Within contact object create three strings variables for first name, last name, and email address.
|Label|Name|Type|Mandatory|
|-----|----|----|---------|
|contacts|contacts|Array.Object|True|
  1. Expand the contacts Array.Object, and rename the child object to contact.

  2. From the row for the contact object, select the Add Child Item icon

Image omitted: icon-add-child-item.png
No alternative text supplied

.

  1. Configure the child item with these values.

    LabelNameTypeMandatory
    first namefirst_nameStringTrue
  2. From the row for the contact object, select the Add Child Item icon

Image omitted: icon-add-child-item.png
No alternative text supplied

.

  1. Configure the child item with these values.

    LabelNameTypeMandatory
    last namelast_nameStringTrue
  2. From the row for the contact object, select the Add Child Item icon

Image omitted: icon-add-child-item.png
No alternative text supplied

.

  1. Configure the child item with these values.

    LabelNameTypeMandatory
    email addressemail_addressStringTrue
  2. From the row for the contact Object, select Toggle Advanced Inputs.

  3. From the Advanced Options, select Save As Template.

    The system displays the Save As Template dialog.

  4. For Enter a Name, enter contact.

Image omitted: array-objects-config-script-step-output-variable-template.png
Save the object template with the name contact.
  1. Click Save.

  2. From the Action Outline, select Outputs > Create Output.

  3. Configure the Action Output with these values.

Image omitted: array-objects-config-outputs.png
Create an action output called contacts to store an array of objects.
|Label|Name|Type|Mandatory|
|-----|----|----|---------|
|contacts|contacts|Array.Object|True|
  1. Expand the contacts Array.Object.

  2. From the row for the contact Object, select Toggle Advanced Inputs.

  3. From the Advanced Options, select Structure > Start from Template.

    The system displays Template.

  4. For Template, select the template you previously saved.

    For example, select Global: contact.

  5. Select Exit Edit Mode.

    The System displays the output fields you created.

  6. For contacts, select [step->Script step->contacts].

Image omitted: array-objects-config-outputs-contacts.png
Configure the action output variable to use the contacts data pill from the Script step.
**Note:** You can select the Script step **contacts** data pill from the data panel or from the Data Pill Picker button.
  1. Click Save.

  2. Select Test.

    The system displays the Test Action dialog.

  3. Enter the following test value:

Image omitted: array-objects-test-action-department.png
Select the Development department to test your action.
|Input|Value|
|-----|-----|
|Department|Development|
  1. Select Run Test.

    The system runs the action with the test values provided.

  2. Select Your test has finished running. View the Action execution details.

    The system displays the action execution details.

  3. Review the runtime value for the action Output data.

Image omitted: array-objects-execution-details-page.png
Execution details page for the test results of your custom action.
Although the execution details display the output data as a JSON formatted string, the actual output data type is an array of objects. If you need a string version of your output, you can convert the object into a string using the JSON class. For more information about converting a JSON object into a string, see .

For this example, the contacts object contains an array of contact objects with first name, last name, and email information for three users in the Development department.

```
{
    "contacts": 
        "contact": [
            {
                "email_address": "allyson.gillispie@example.com",
                "first_name": "Allyson",
                "last_name": "Gillispie"
            },
            {
                "email_address": "alva.pennigton@example.com",
                "first_name": "Alva",
                "last_name": "Pennigton"
            },
            {
                "email_address": "andrew.och@example.com",
                "first_name": "Andrew",
                "last_name": "Och"
            }
        ]
    }
}

```

Result

You have a custom action that looks up the Users for a given department and converts those users into an array of contact objects.

What to do next

Customize this action to use your own logic.

Parent Topic:Script support for complex data