How to populate the current logged in user to caller field if no value present.

k chaitanya kum
Giga Contributor

How to populate the current logged in user to caller field if no value present.

1 ACCEPTED SOLUTION

Hello,

the initialization of the default value for the caller field auto populate the caller field when a new incident is inserted.

I assume that your use case is when an existing incident is existing and for an unknow reason, the caller field is empty ... That shouldn't happen if you set the caller field mandatory ...

To give you the technical answer, please find below the client script code :

function onLoad() {
	
	var userID = g_user.userID;
	
	if (g_form.getValue('caller_id') == '')
		g_form.setValue('caller_id', userID);
	
}

 

View solution in original post

10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Chaitanya,

At the dictionary level have the default value as javascript: gs.getUserID() for that field.

Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Thanks bro

k chaitanya kum
Giga Contributor

My qution is : populate the current logged in user to caller field if no value present

and iam tryed this code in client script onLoad() but its not executed

var a=g_form.getValue('caller_id');
if(a == null)
{
var b=g_user.userID;
g_form.setValue('caller_id',b);
}

Try below code:

alert(g_user.userID;);

var a=g_form.getValue('caller_id');
if(a =='')
{
g_form.setValue('caller_id',g_user.userID;);
}