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

yes right you can remove that please use below in client script:-

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
   
   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. 

Aman66
Tera Contributor

It is not working .Have you checked it in your side

Yes it works for me perfectly. in the script include have to checked the client callable checkbox

Aman66
Tera Contributor

hi ,

this script also don't work in my friend side . I don't know what is happening in my side

 

can you share the screenshot of the client script and script include. Also share a screenshot of the fields

 

Also, hopefully on the script include you have made checked the client callable field.

 

Saurav11_0-1665753021884.png

 

Please mark my answer as correct based on Impact.