How to prevent duplicate records in sys_user_grmember?

AyushK859766811
Mega Explorer

We are seeing duplicate records in the sys,user,grmember table where the same user is added to the same group multiple times. This usually happens due to automated scripts, Flow Designer actions, or integrations that add group members without checking existing membership first.

What is the recommended best practice in ServiceNow to prevent these duplicate user and group records from being created?

5 REPLIES 5

lpruit2
Kilo Sage

Greetings @AyushK859766811. My initial thought was to do a Business Rule on the Group Member table [sys_user_grmember] using a simple GlideRecord query that adds Query conditions for the Group and User values from the current record and then utilizes a .hasNext() method to abort the action. However, when I went to test this Business Rule in my Personal Development Instance (PDI), I wasn't able to recreate a duplicate entry on the Group Member table without the need of any new Business Rule.

 

I tried using a Background Script to do a GlideRecord insert in addition to navigating to the Group Member table and clicking the New button. 

t-powers
Giga Contributor

First reply 🙂

When a user is added, does that record autogenerate a unique ID?

t-powers
Giga Contributor

Are unique IDs generated when a user is added? If not, can they be auto-generated to identify these things?

544341796
Mega Contributor

It's useful.