Removal users through catalog Request

harinya
Tera Contributor

Hi Team,

I have created a catalog item with two variables:

  1. Entities (List Collector)

  2. Users Removal (List Collector)

Requirement:
Based on the selected entities and users, the selected users should be removed from the respective Entity Stakeholder records (sn_grc_entity_stakeholder) from the user field.

Current Flow Design:

  • Trigger: Service Catalog Requested Item

  • Lookup Entity Stakeholder records based on:

    • Entity is one of selected entities

  • For Each Entity Stakeholder record

  • Created a custom Flow Action with inputs:

    • Current Users

    • Users To Remove

  • In the Action script, comparing current users and removing selected users, then returning updated users output.

  • Finally updating the Entity Stakeholder user field with updated users output.

Action Script:

(function execute(inputs, outputs) {

    var currentUsers = inputs.current_users.split(',');
    var removeUsers = inputs.users_to_remove.split(',');

    var updatedUsers = [];

    for (var i = 0; i < currentUsers.length; i++) {

        var user = currentUsers[i].trim();

        if (removeUsers.indexOf(user) == -1) {
            updatedUsers.push(user);
        }
    }

    outputs.updated_users = updatedUsers.join(',');

})(inputs, outputs);

Issue:
When testing the Action manually with sample values, it works correctly.

Example:

Current Users:

user1,user2,user3

Users To Remove:

user2

Output:

user1,user3

But during actual Flow execution:

  • updated_users output is coming empty

  • Sometimes debug output shows values like:

[object GlideRecord]

instead of comma-separated sys_ids

  • Because of this, the user field is getting updated as empty.

I already verified:

  • Action inputs are configured as String type

  • Passing:

    • For Each → Entity Stakeholder → User List

    • Catalog Variables → Users Removal

  • Both Entity Stakeholder records and User List values are present correctly

Could someone please suggest the best approach to handle glide list/user list values in Flow Designer for this scenario?

Thanks in advance.

8 REPLIES 8

@harinya 

share how you are calling this from your flow and how are you sending the input?

šŸ’” 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

ziarahman
Tera Contributor

Update action script with this

 

(function execute(inputs, outputs) {

 

    function normalizeToArray(value) {
        if (!value) return [];

 

        // If already array
        if (Array.isArray(value)) {
            return value.map(function(v) {
                return v.toString().trim();
            });
        }

 

        // If GlideRecord or object
        if (typeof value === 'object') {
            try {
                return value.toString().split(',');
            } catch (e) {
                return [];
            }
        }

 

        // If string
        return value.toString().split(',');
    }

 

    var currentUsers = normalizeToArray(inputs.current_users);
    var removeUsers = normalizeToArray(inputs.users_to_remove);

 

    var updatedUsers = [];

 

    for (var i = 0; i < currentUsers.length; i++) {
        var user = currentUsers[i].trim();

 

        if (user && removeUsers.indexOf(user) === -1) {
            updatedUsers.push(user);
        }
    }

 

    outputs.updated_users = updatedUsers.join(',');

 

})(inputs, outputs);
 

@ziarahman Thanks for the Response , i tried this way but seems not working getting same like earlier updated users are coming as empty value

Juhi Poddar
Kilo Patron

Hello @harinya,

It seems the issue is related to the values being passed into the custom Flow Action rather than the Action script itself.

Based on the behavior you're describing and the screenshots shared, the inputs do not appear to be getting passed as a comma-separated list of sys_ids.

 

When Flow Designer receives a GlideRecord or record object instead of a string, it can result in values such as: [object GlideRecord]

 

which would explain why your script is unable to split and compare the values correctly, causing the updated_users output to be empty.

 

I was able to replicate a similar scenario in my PDI, and the custom Action worked as expected when the inputs were passed directly as the sys_id values from the List Collector variable.

JuhiPoddar_0-1780570640086.png

I would recommend verifying that:

  • The Current Users input is receiving the actual glide list value (comma-separated sys_ids).
  • The Users To Remove input is mapped directly from the List Collector variable.
  • No record objects or GlideRecord references are being passed into the Action inputs.
  • There doesn't appear to be an issue with the Action script itself. The focus should be on ensuring the inputs are passed in the correct format.

Hope this helps!

 

Thank You!
Juhi Poddar