Set Caller, Email in incident form.

niveditakumari
Mega Sage

Hi, 

 

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

 

Regards, 

Nivedita

 

 

1 ACCEPTED SOLUTION

AnubhavRitolia
Mega Sage
Mega 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.

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

View solution in original post

4 REPLIES 4

AndersBGS
Tera Patron
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

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

AnubhavRitolia
Mega Sage
Mega 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.

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

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