How do I populate a field like gs.getUserID() does?

Shane J
Tera Guru

I'd like to build a Template to allow the auto-fill of Assignment Group from the User record, using a field called 'u_main_group' (similar to using javascript:  gs.getUserID()).  I've used Script Includes to limit options before, but never to populate a field like that.  

How would I do that?  Is that even the right approach?

1 ACCEPTED SOLUTION

SanjivMeher
Kilo Patron
Kilo Patron
You can use the default field to set the assignment group. In the default field set JavaScript: var u = new GlideRecord('sys_user'); u.get(gs.gerUserID());u.u_main_group;

Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

6 REPLIES 6

rob_pastore
ServiceNow Employee
ServiceNow Employee

Use gs.getUser() -this returns the user record instead of just the user ID.

 

var user = gs.getUser();

 

you can then populate the assignment group with:

user.u_main_group.sys_id

Kunal Jha
Giga Expert

Auto fill assignment group from caller record ?If yes then I dont think this approach will be able to target global audience. If end user in not part of any group then it will create issue.

But to accomplish what you wanted you should write script include and call it in the dictonary level of that field under reference qualifier.

I'm trying to populate the field when a Template is used, not by default.

SanjivMeher
Kilo Patron
Kilo Patron
You can use the default field to set the assignment group. In the default field set JavaScript: var u = new GlideRecord('sys_user'); u.get(gs.gerUserID());u.u_main_group;

Please mark this response as correct or helpful if it assisted you with your question.