Set Caller, Email in incident form.

niveditakumari
Giga Sage

Hi, 

 

Set Caller, Email in incident form. When form loads set Caller Name, Email with client script. 

 

Regards, 

Nivedita

 

 

1 ACCEPTED SOLUTION

anubhavritolia
Giga Sage

Hi @niveditakumari 

 

Here either you can simply dot walking email field from User table on Incident form as 'Caller.Email' from form layout, This will automatically update Email value on Incident table when Caller changes.

 

2nd solution is by using onChange Client script as below:

 

function onChange(control, oldValue, newValue, isLoading) 
{ 

if(isLoading || newValue == '')
{
g_form.setValue('caller_id',g_user.userID);
}

var caller = g_form.getReference('caller_id', doAlert);

function doAlert(caller) { 
g_form.setValue('u_caller_email',caller.email); // assuming 'Caller Email' [u_caller_email] is custom field to store Caller Email
}

 

I know getReference() is not recommended by ServiceNow but for fetching 1 or 2 values we can use it.

 

View solution in original post

4 REPLIES 4

AndersBGS
Tera Patron

Hi @niveditakumari ,

 

What is the source table where you receive the caller from,  and what is the expected field and table where email should be set?

 

best regards

Anders

anubhavritolia
Giga Sage

Hi @niveditakumari 

 

Here either you can simply dot walking email field from User table on Incident form as 'Caller.Email' from form layout, This will automatically update Email value on Incident table when Caller changes.

 

2nd solution is by using onChange Client script as below:

 

function onChange(control, oldValue, newValue, isLoading) 
{ 

if(isLoading || newValue == '')
{
g_form.setValue('caller_id',g_user.userID);
}

var caller = g_form.getReference('caller_id', doAlert);

function doAlert(caller) { 
g_form.setValue('u_caller_email',caller.email); // assuming 'Caller Email' [u_caller_email] is custom field to store Caller Email
}

 

I know getReference() is not recommended by ServiceNow but for fetching 1 or 2 values we can use it.

 

Hi Anubhav, 

 

Thank you so much for your reply. 

Can you please confirm field name for email in incident form. 

 

Regards, 

Nivedita

 

 

Hi Anubhav, 

 

Script which you given that will work for 'onload' script and 'onchange' script right. 

ex - When we load forms then 'CallerID' and Caller 'emaiID' will get autopopulate and when we change CallerID then based on CallerID it will change caller's email id right. 

Can you please confirm for this. 

 

Regards, 

Nivedita