Populate Assignment Group & Assigned To based on the logged in user and their Primary Group

RichardSaunders
Tera Guru

I need to be able to populate the Populate Assignment Group & Assigned To for service desk staff only. This should not happen to users using the self service portal.

I have experimented with default value: javascript:gs.getUserID() and assignment rules but can not get it working.

any advise/pointers?

1 ACCEPTED SOLUTION

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);


}


}


}


View solution in original post

20 REPLIES 20

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>');


Incredible. Thank you so much. This is exactly what i was looking for. I still have a way to go with my JavaScript knowledge so thanks again.


Just one more thing, how would i add an if condition of...


contact_type is not self-service, or contact_type is phone?



You would need to add another variable to get the value of the contact type, similar to how it checks if the assignment group is empty.




Something like:



var ctype = g_form.getValue('contact_type');



if(ctype == 'phone'){


//add code here


}



OR


if(ctype != 'self-service'){


//add code here


}



The location where you put this 'if' condition will just depend on what you're trying to accomplish.


Hi, 

 

I know this is an old thread, however i hope you can help, i used your script and it works brilliantly. Is there a way to change it to OnChange? We have rules based on the business service to populate the assignment group, but in the instance where the assignment group is removed and is assigned directly to a person, we want the assignment group to populate with the assigned to primary support group. Is that possible?