How do I populate current logged in user as Assigned To?

Sid_Takali
Kilo Patron
Kilo Patron

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?

11 REPLIES 11

SatyakiBose
Mega Sage

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?

@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. 

@Sid_Takali 

so what script did you try so far?

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Ankur Bawiskar 

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

@Sid_Takali 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader