---
sourceDocument: Australia Build workflows
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/build-workflows

 Release :

    - australia

ft:locale :

    - en-US

ft:publication_title :

    - Australia Build workflows

ft:clusterId :

    - crworkflow

bundleId :

    - crworkflow

workflow :

    - Creator


---

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

# Create a custom action to generate an array of strings from a list of records {#ariaid-title1}

* Release version: Australia
* 
* Updated March 12, 2026
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 3 minutes to read

Generate an array of strings from a list of User Role 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 Role record.
* Look up a maximum of three User Role records that have the Role action input.
* Configure a Script step to process a list of User Role records.
* Create a script input variable containing the list of User Role records.
* Write script that creates an empty users array.
* Write script that iterates through the list of User Role records.
* Write script that populates the users array with the current user field value.
* Create script output variables for the users array and child user string.
* Output the generated users array of strings as a data pill.
* Test the action with three sample users.
{#create-custom-action-array-strings__ul_c5v_rdw_lhb}

## Procedure

1. **Optional:** 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 [Building apps in App Engine Studio](https://www.servicenow.com/docs/access?context=aes-app-creation&version=australia&pubname=australia-application-development&ft:locale=en-US).  
   For example, create an application called <kbd class="ph userinput">My Application</kbd>.
2. Navigate to AllProcess AutomationWorkflow Studio.
3. On the homepage, select Actions.
4. Select NewAction  
   The system displays the Action Properties dialog.
5. Enter these sample values.  
   {#create-custom-action-array-strings__table_tjt_xxp_lhb__entry__2}

   | Field | Value |
   |-|-|
   | Name | Create Users With Role Array Of Strings |
   | Application | Global |
   | Accessible From | All application scopes |
   [ ]

   {#create-custom-action-array-strings__table_tjt_xxp_lhb}  
   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 InputsCreate Input  
   The system displays a new action input.
8. Configure the action input with these values.  
   {#create-custom-action-array-strings__table_ijj_myp_lhb__entry__2}

   | Field | Value |
   |-|-|
   | Label | Role |
   | Type | Reference.Role \[Reference.sys_user_role\] |
   | Mandatory | True |
   [ ]

   {#create-custom-action-array-strings__table_ijj_myp_lhb}
9. From the Action Outline, select Add a new step.  
   The system displays a list of available steps.
10. Select Look Up Records
11. Configure the step with these values.  
    {#create-custom-action-array-strings__table_cvp_l5p_lhb__entry__2}

    | Field | Value |
    |-|-|
    | Table | User Role \[sys_user_has_role\] |
    | Conditions | \[Role\]\[is\]\[action-\>Role\] Note: Select the Role data pill from the Input Variables. |
    | Order by | Role |
    | Sort Type | a to z |
    | Max Results | 3 |
    [ ]

    {#create-custom-action-array-strings__table_cvp_l5p_lhb}  
    Note:  
    This example limits the Max Results setting to three records just for demonstration purposes.
12. From the Action Outline, select Add a new step.  
    The system displays a list of available steps.
13. Select Script.
14. From the Input Variables section, select Create Variable.
15. Configure the input variable with these values.  
    {#create-custom-action-array-strings__table_uby_5zp_lhb__entry__2}

    | Field | Value |
    |-|-|
    | Name | userRoleRecords |
    | Value | \[step-\>Look Up Records step-\>User Role records\] Note: Select the User Role records data pill from the Look Up Records step. |
    [ ]

    {#create-custom-action-array-strings__table_uby_5zp_lhb}  
    Note:  
    You can select the User Role records data pill from the data panel or from the Data Pill Picker button.
16. For Script, enter the following text.  

        (function execute(inputs, outputs) {
          //Create an empty array
          var usersArray = [];
          var i = 0;
          //Iterate through the list of User Role records
          while(inputs.userRoleRecords.next()) {
            //Query User Role records for user field value
            var user = inputs.userRoleRecords.getDisplayValue('user');
            //Add current user name to array
            usersArray[i] = user;
            i += 1;
          }
          outputs.users = usersArray;
        })(inputs, outputs);

17. From Output Variables, select Create Variable.
18. Configure the output variable with these values.  
    {#create-custom-action-array-strings__table_e3w_hbq_lhb__entry__4}

    | Label | Name | Type | Mandatory |
    |-|-|-|-|
    | users | users | Array.String | True |
    [ ]

    {#create-custom-action-array-strings__table_e3w_hbq_lhb}
19. Expand the users Array.String, and rename the child string to <kbd class="ph userinput">user</kbd>.
20. Configure the child item with these values.  
    {#create-custom-action-array-strings__table_d3v_sbq_lhb__entry__4}

    | Label | Name | Type | Mandatory |
    |-|-|-|-|
    | user | user | String | False |
    [ ]

    {#create-custom-action-array-strings__table_d3v_sbq_lhb}
21. From the Action Outline, select OutputsCreate Output.
22. Configure the Action Output with these values.  
    {#create-custom-action-array-strings__table_ojs_pcq_lhb__entry__4}

    | Label | Name | Type | Mandatory |
    |-|-|-|-|
    | users | users | Array.String | True |
    [ ]

    {#create-custom-action-array-strings__table_ojs_pcq_lhb}
23. Expand the users Array.String, and rename the child string to <kbd class="ph userinput">user</kbd>.
24. Configure the child item with these values.  
    {#create-custom-action-array-strings__table_qcx_t1t_rbc__entry__4}

    | Label | Name | Type | Mandatory |
    |-|-|-|-|
    | user | user | String | False |
    [ ]

    {#create-custom-action-array-strings__table_qcx_t1t_rbc}
25. Select Exit Edit Mode.  
    The System displays the output fields you created.
26. For users, select \[step-\>Script step-\>users\].  
    Note:  
    You can select the Script step users data pill from the data panel or from the Data Pill Picker button.
27. Click Save.
28. Select Test.  
    The system displays the Test Action dialog.
29. Enter the following test value:  
    {#create-custom-action-array-strings__table_onv_z22_mhb__entry__2}

    | Input | Value |
    |-|-|
    | Role | admin |
    [ ]

    {#create-custom-action-array-strings__table_onv_z22_mhb}
30. Select Run Test.  
    The system runs the action with the test values provided.
31. Select Your test has finished running. View the Action execution details.  
    The system displays the action execution details.
32. Review the runtime value for the action Output data.  
    The system displays output data in JSON format.  
    For this example, the users array contains three users who have the admin role.

        {
            "users": [
                "System Administrator",
                "Rob Phillips",
                "Fred Luddy"
            ]
        }

## Result

You have a custom action that looks up the Users who have a given role and converts those users into an array of user name strings.

## What to do next

Customize this action to use your own logic.

*[\>]: and then


