The CreatorCon Call for Content is officially open! Get started here.

onchange client script

Aman66
Tera Contributor

Hi all ,

use case - write a Onchange client script and script include also to Automatic add caller manager into watchlist when i change caller field in the incident form .

 

please help me to do this use case 

1 ACCEPTED SOLUTION

Hello,

 

Please create a script include with name Getemail as below:-

 

Saurav11_0-1665736335769.png

 

Write the below code in script include:-

 

var Getemail = Class.create();
Getemail.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
	getemail: function() {
	var email=this.getParameter('sysparm_email');
   
   var gr=new GlideRecord('sys_user');
   gr.addQuery('sys_id',email);
   gr.query();
	if(gr.next());
	{
		return gr.manager;
	}
	},

    type: 'Getemail'
});

 

Then use the below code in onchange client script:-

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
   
 var email=g_form.getValue('email');
   var ga = new GlideAjax("Getemail");
    ga.addParam('sysparm_name', 'getemail');
    ga.addParam('sysparm_email',newValue);
    ga.getXML(callback);

    function callback(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        g_form.setValue('watch_list', answer);
    }
		
}

 

Please mark my answer as correct based on Impact. 

View solution in original post

28 REPLIES 28

Aman66
Tera Contributor

hi sir ,

can i show my script what i have done 

suvro
Mega Sage

Hi Aman,

 

Please go through the below article it has detailed steps to use Client Script and Call Script Include by using GlideAjax

https://www.servicenow.com/community/it-service-management-articles/how-to-fetch-other-details-of-th...

AnubhavRitolia
Mega Sage

Hi @Aman66 

 

Can you try by replacing 'sysparm_sys_ids' to 'sysparm_sysID'. May be douple underscore is issue. Try to keep it 1 only and try.

 

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

Jyo1231
Tera Contributor

There are two typos in your client script. 

1. document written as doucument

2. Name of the function in the GlideAjax part. It says 'return_manger_value' instead of 'return_manager_value'