Flow Designer script action

harinya
Tera Contributor

Hi 

I am working on a Service Catalog Item for a user removal process and would appreciate some guidance on the best approach.

Requirement

I have created a Catalog Item with the following variables:

  1. Entities – Reference field to the Entity table.

  2. Delegates – List Collector (auto-populated from stakeholder table which is having entity field).

  3. Remove Delegates – List Collector where users select the delegates to be removed.

  • the Delegates field is auto-populated with users from the corresponding  Stakeholder record.

  • The Stakeholder table contains a user_list field (Glide List) that stores the delegate users.

  • Users select one or more users in the Remove Delegates field which are present in the delegate suers field

Expected Outcome

For example:

  • Delegates: User A, User B, User C, User D

  • Remove Delegates: User B, User D

After submission, the Stakeholder user_list field should be updated to:

  • User A, User C

In other words, I need to remove the selected users from the existing delegate list and update the stakeholder record with the remaining users.

Challenge

I initially tried implementing this using a Custom Action in Flow Designer, but I am facing issues because the List Collector values are being passed as objects/records rather than simple comma-separated sys_id strings. While debugging, the inputs appear as objects (showing sys_meta and other record information) instead of the expected Glide List values.

Questions

  1. What is the recommended approach to compare two List Collector/Glide List values in Flow Designer?

  2. Is there a standard way to convert List Collector values into a comma-separated sys_id string within Flow Designer or a Custom Action?

  3. Has anyone implemented a similar "remove selected users from an existing Glide List" requirement without using Script Steps(inline script will not allow the client)?

  4. Would a For Each loop approach be more suitable than a Custom Action for this scenario?

    harinya_0-1781605353547.png
    harinya_1-1781605468659.png

     


    inputs i have taken as the array.string(string, array.object )all i tried but the updtaed users is coming as empty

Any suggestions, examples, or best practices would be greatly appreciated.

Thank you!

2 REPLIES 2

Yogesh11bhatt
Kilo Guru

Hi @harinya ,

 

What you're experiencing is a common Flow Designer behavior when working with Catalog Item List Collectors and Glide List fields.

Although a Glide List is ultimately stored as a comma-separated string of sys_ids in the database, Flow Designer often deserializes List Collector values into record collections (Array.Object, Array.Reference, or Array.String) at runtime. That's why you're seeing record metadata (sys_meta, etc.) instead of simple sys_id strings.

Why your current action is returning an empty result

Based on your screenshots, the most likely cause is a data type mismatch:

  • One collection contains record objects.

  • The comparison logic expects native strings/sys_ids.

  • Comparing a complex object to a string will never match, resulting in an empty output array, which then .join(',') turns into an empty string.

Recommended Approach

I highly recommend keeping your Custom Action (and avoiding Flow Designer For Each loops, which add unnecessary execution overhead and database threads for simple array subtraction).

You just need a script that normalizes both inputs to primitive sys_id strings before performing the comparison. Because Flow Designer's script engine can be finicky with object wrappers, here is a robust approach to achieve exactly what you need.

1. Configure your Action

  • Inputs: current_users and users_to_remove (configure the inputs to match the data type being passed by Flow Designer—Array.String, Array.Object, or Array.Reference depending on the source data pill).

  • Output: updated_users (set this to type String).

2. Use this Script

(function execute(inputs, outputs) {
    var currentUsers = inputs.current_users || [];
    var usersToRemove = inputs.users_to_remove || [];

    // Helper to safely extract a primitive sys_id from Flow Designer objects or strings
    function getSysId(val) {
        if (!val) return '';
        if (typeof val === 'string') return val.trim();
        if (typeof val === 'object' && val.sys_id) return val.sys_id.toString();
        return val.toString();
    }

    // Build a fast lookup map for users to remove
    var removeMap = {};
    for (var i = 0; i < usersToRemove.length; i++) {
        var sysId = getSysId(usersToRemove[i]);
        if (sysId) removeMap[sysId] = true;
    }

    // Filter the existing users
    var updatedUsers = [];
    for (var j = 0; j < currentUsers.length; j++) {
        var currSysId = getSysId(currentUsers[j]);
        if (currSysId && !removeMap[currSysId]) {
            updatedUsers.push(currSysId);
        }
    }

    // Output the final comma-separated string to update the Glide List
    outputs.updated_users = updatedUsers.join(',');
})(inputs, outputs);

Once this runs, simply drag the String output pill directly into an Update Record action for your Stakeholder's user_list field.

What to Verify Next

If you still face issues, open your Action Execution Details, inspect one element from the inputs, and confirm whether the payload contains:

{"sys_id":"..."}

or

62826bf03710200044e0bfc8bcbe5df1

The script above safely handles both, but verifying the payload will help you understand exactly how your specific catalog variables are being handed to Flow Designer.

Hope this helps!

 

Please mark this answer as Helpful if it resolves your question. 🙂

 

Thanks,
Yogesh Bhatt

Ankur Bawiskar
Tera Patron

@harinya 

Approach

1) use 2 flow variables 1 for each list collector

2) use Set Flow Variables flow logic to set the flow variables and store comma separated sysIds in that using script

3) then pass these 2 flow variables to your custom flow action and then handle the logic in script

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader