Populate the logged in user's group

Samiksha2
Mega Sage

Hi All,

 

I have created a Reference field in the Requested Item.(Requester Group- Reference to sys_group table). 

The requirement is to show the logged in user's group in that field without adding any reference qualifier in the dictionary because this field is been used in other scripts.

Samiksha2_0-1694760919710.png

Please help in this. 

 

Thanks,

Samiksha

1 ACCEPTED SOLUTION

@Samiksha2 

Please use the following BR with the script to populate the first group upon RITM creation.

 

(function executeRule(current, previous /*null when async*/ ) {
    var gr = new GlideRecord("sys_user_grmember");
    gr.addQuery("user", current.requested_for);
    gr.query();
    if (gr.next()) {
        current.u_requester_group = gr.getValue('group'); //Change field name as per your configuration
    }
})(current, previous);

 

AnveshKumarM_0-1694763427193.png

 

Thanks,
Anvesh

View solution in original post

7 REPLIES 7

AnveshKumar M
Tera Sage
Tera Sage

Hi @Samiksha2 

What if the user is member of multiple groups?

Thanks,
Anvesh

Hi @AnveshKumar M ,

Thanks for your reply. 

It should populate the 1st group.

Thanks,

Samiksha

@Samiksha2 

Please use the following BR with the script to populate the first group upon RITM creation.

 

(function executeRule(current, previous /*null when async*/ ) {
    var gr = new GlideRecord("sys_user_grmember");
    gr.addQuery("user", current.requested_for);
    gr.query();
    if (gr.next()) {
        current.u_requester_group = gr.getValue('group'); //Change field name as per your configuration
    }
})(current, previous);

 

AnveshKumarM_0-1694763427193.png

 

Thanks,
Anvesh

To populate Logged in user (requester) group, instead of requested for use the following script.

 

(function executeRule(current, previous /*null when async*/ ) {
    var gr = new GlideRecord("sys_user_grmember");
    gr.addQuery("user", gs.getUserID());
    gr.query();
    if (gr.next()) {
        current.u_requester_group = gr.getValue('group'); //Change field name as per your configuration
    }
})(current, previous);
Thanks,
Anvesh