How do I populate current logged in user as Assigned To?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2023 11:38 PM
I want to auto populate current logged in user as Assigned To and current logged in user's Primary assignment Group as Assignment Group on Case form. Now I have created Display BR and getting current userID and passing it onLoad Client Script through scratchpad variable. but it is not working in workspace. I have made Client Script UI Type for "All". I want know alternative ways for this use case?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2023 01:06 AM
Hi @Sid_Takali
My first question to you would be WHY ?
The current user could be an end user or an affected user. Populating their name in assigned to and groups in assignment group would go against the working principles of ITIL.
May i know thw business use case to implement this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2023 02:44 AM
@SatyakiBose & @Ankur Bawiskar We are developing CSM Application. The user here is Agents who creates case on behalf of Customer/Consumer. So I want to populate Current Logged in User and his/her Primary Assignment Group in Assigned to and Assignment Group respectively.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2023 03:07 AM
so what script did you try so far?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2023 09:04 AM
in Display BR getting user and user's Primary Assignment Group in Scratchpad variable and passing t to client script
Display BR
g_scratchpad.userObj = gs.getUserID();
var userName = gs.getUserID();
var gr = new GlideRecord("sys_user");
gr.addQuery('sys_id', userName);
gr.query();
if (gr.next()) {
g_scratchpad.priGrp = gr.getValue('primary_group');
return g_scratchpad.priGrp;
}
onLoad Client Script
if (g_form.isNewRecord()) {
g_form.setValue('assigned_to', g_scratchpad.userObj);
g_form.setValue('assignment_group', g_scratchpad.priGrp);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2023 07:35 PM
try this
Display BR
var userName = gs.getUserID();
var gr = new GlideRecord("sys_user");
gr.addQuery('sys_id', userName);
gr.query();
if (gr.next()) {
g_scratchpad.priGrp = gr.getValue('primary_group');
}
client script
if (g_form.isNewRecord()) {
g_form.setValue('assigned_to', g_user.userID);
g_form.setValue('assignment_group', g_scratchpad.priGrp);
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader