Autofill Primary group when a user added to some specific group.

Rakesh Behera
Tera Contributor

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

@Ankur Bawiskar 

@Mark Roethof 

@Kalaiarasan Pushpanathan 

@Sandeep Dutta 

@Aman Kumar 

@Musab Rasheed 

@Mohith Devatte 

 

5 REPLIES 5

@Rakesh Behera 

Glad to know.

Please mark my response as correct and close the thread.

Regards
Ankur

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