How to populate Primary Assignment Group of a logged in user in Assignment Group on a Incident form

Sid_Takali
Kilo Patron
Kilo Patron

Hi all,

I have a requirement where I have to auto populate a Assigned To and Assignment Group field on Incident form with logged in user and his/her Primary Assignment Group. 

6 REPLIES 6

Basheer
Mega Sage

Hi @Sid_Takali ,

You can write an onLoad Client script + Display BR to achieve this.

In Display BR

g_scratchpad.userObj = gs.getUser();
g_scratchpad.priGrp = gs.getUser().u_primary_assignee_group; // If you have the assignment group field

In Client Script

g_form.setValue("assigned_to",g_scratchpad.userObj);
g_form.setValue("assignment_group",g_scratchpad.priGrp);

 

Please hit like button if my suggestion has helped you in any way.
Please mark correct if my response has solved your query.

Cheers,
Mohammed Basheer Ahmed.

Hi @Sid_Takali ,

As you are doing it on client level prefer not to use GlideRecord object or getReference object, Instead go for Display BR as mentioned or go for GlideAjax using Script Include. You may get the values from GlideRecord or getReference but they will impact the load time of the form.

 

Please hit like button if my suggestion has helped you in any way.
Please mark correct if my response has solved your query.

Cheers,
Mohammed Basheer Ahmed.

SoniaShridhar13
Giga Guru

@Sid_Takali Hi! 

Is this what you are looking for with an onLoad client script?



function onLoad() {

 

//Type appropriate comment here, and begin script below

 

var grp = g_form.getValue('assignment_group');

 

if (grp == ''){

 

var userName = g_user.userName;//logged in user



var gr = new GlideRecord("sys_user");//check if the logged in user has a primary group

 

gr.addQuery('user_name', userName);

 

gr.addQuery('u_primary_group', '!=', '');

 

gr.query();

 

if (gr.next()){//logged in user is a member of assignment group

 

g_form.setValue('assignment_group', gr.u_primary_group);

 

g_form.setValue('assigned_to', g_user.userID);

 

}

 

}

 

}

SoniaShridhar13
Giga Guru

@Sid_Takali  

And if you want to restrict this to users with a specific primary group, you could change this line:

 

gr.addQuery('u_primary_group', '!=', '');

 

to this:

 

gr.addQuery('u_primary_group',   '<specific group's sys_id>');

 

Please mark my answer helpful of it helps...