Flow designer remove user action not working

Burhan2
Tera Contributor

I have a flow where reqfor user should be automatically removed from group when requested. We have a list collector group field and when submitted reqfor user should be removed from the mentioned groups in that field . I created action for that but it seems deleteRecord() method is not working in flow...the script was working fine in workflow and user was getting removed.. I have also automation to Adduser and that is working correctly can nyone help me in this

Attaching script for removal from action.:-group.pngremove.png

(function execute(inputs, outputs) {
var req_for = inputs.Reqfor;
var team = inputs.Grouplist.toString().split(',');
var addorremove=inputs.AddorRemove;
if (addorremove == 'Add') {
    for (var i = 0; i < team.length; i++) {

        var grpMembr = new GlideRecord('sys_user_grmember');
        grpMembr.addQuery('group', team[i]);
        grpMembr.addQuery('user', "!=", req_for);
        grpMembr.query();
        while (grpMembr.next()) {
            grpMembr.initialize();
            grpMembr.group = team[i];
            grpMembr.user = req_for;
            grpMembr.insert();
        }

    }
}
else if (addorremove == 'Remove') {
   
        for (var i = 0; i < team.length; i++) {

        var grpMembr = new GlideRecord('sys_user_grmember');
        grpMembr.addQuery('group', team[i]);
        grpMembr.addQuery('user', "=", req_for);
        grpMembr.query();
        while (grpMembr.next()) {
        grpMembr.deleteRecord();
        }

   
}

    }


})(inputs, outputs);
1 ACCEPTED SOLUTION

@Burhan2 

Below is the working solution, user was part of 2 groups and flow ran and removed that user from those groups

flow remove user from group.gifflow remove user from group 1.gif

I believe I have provided enough guidance and responded to all your questions.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

33 REPLIES 33

Abhijeet_Pawar
Tera Guru

Hello @Burhan2 

Could you please share a screenshot of the error you're encountering? Additionally, have you confirmed whether your else block is being executed by adding some logs for verification?

Thank you!

yes its getting executed @Abhijeet_Pawar  just check the ss i have attached now while i am testing the action so its working but in flow its not working and adduser is working correctly and same is used for remove user but don't know through flow remove user is not working

Ankur Bawiskar
Tera Patron
Tera Patron

@Burhan2 

is assignment_group variable a list collector?

Did you see the script received the inputs correctly?

Script is correct. seems issue with the input

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Yes @Ankur Bawiskar assignment_group field is list collector also i just checked and did test action so for that the user got removed from the group but with flow its not getting removed when raising request ill also share ss where i am getting all data in workflow context but still user is not getting removedss.png