Autofill Primary group when a user added to some specific group.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 01:37 AM
Hi All,
I have a custom field "Primary group" in user table which is reference to group table.
There are some particular group if the user is added to any of those groups then his primary group will be auto-filled with that group. I tried to achieve this through BR in User table but my code is not working as expected.
Use this piece of code:
var userGrp = new GlideRecord('sys_user_grmember');
userGrp.addQuery('user', current.sys_id); userGrp.addEncodedQuery('group=8a4dde73c6112278017a6a4baf547aa7^ORgroup=287ebd7da9fe198100f92cc8d1d2154e^ORgroup=287ee6fea9fe198100ada7950d0b1b73');
userGrp.query();
if (userGrp.next()) {
current.u_primary_group = userGrp.group;
current.update();
And put this condition in when to run :
After Insert &Update
Active is True
and
Primary support group is empty.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2022 11:29 PM
Glad to know.
Please mark my response as correct and close the thread.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader