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.

6 REPLIES 6

Tanushree Maiti
Tera Patron

Hi @harinya 

 

Just Change this two lines ->publish and test in real time execution

 

From:

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

To:

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

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

Hi @Tanushree Maiti Thanks for Response i tried this approach but didn't worked

Ankur Bawiskar
Tera Patron

@harinya 

the action inputs are of what type?

share screenshots of the flow action for each step

 

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

harinya_0-1780566125443.pngharinya_1-1780566168001.png

script  is:

(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);

harinya_2-1780566407450.png

 

harinya_3-1780566466022.png

harinya_4-1780566536774.png

@Ankur Bawiskar Thanks for the Response i have shared all snaps if u can please help.