Flow duplicating users in a group

ClareM
Tera Expert

Hi,

 

I've updated my post with screenshots to provide more details

 

I've created a flow that runs on an approver table when a record is created or updated. If the approver field changes it checks if the approver is in the approver group and if not, adds them.

 

The issue is if multiple records are updated at the same time, the approver gets added to the group multiple times.

 

Is there a way to prevent this? I wondered if using a queue would solve the issue? I'm not sure how queues work in SNow.

 

Flow

ClareM_0-1750764985707.png

Sub flow - checks if user exists in group before adding

ClareM_1-1750765029287.png

Users updated in bulk in list edit view are added multiple times

ClareM_2-1750765175870.png

 

 

Thanks,

 

Clare

10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

@ClareM 

in flow check if the user is already part of that group

If not then only add

If yes then don't add and end the flow.

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

Hi Ankur, 

I've updated my post with screenshot to provide further detail. I am already checking if the user is a member of the group before adding them. The issue is where the user is being added for more than 1 record at the same time.

Thanks, Clare

@ClareM 

out of the box it does allow duplicates.

You can use before insert business rule and handle and abort

var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("group", current.group);
gr.addQuery('user', current.user);
gr.query();
if (gr.hasNext()) {
    current.setAbortAction('true');
}

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

Hi Ankur, 

Would this not have the same result as the flow if records are being updated at the same time? 

I had started out with a business rule but ran into some issues which I thought was due to the logic being too complex.

Thanks,

Clare