Script include and Client script

Ashish Khairnar
Tera Contributor

I am currently working on a requirement where I need to populate the manager's name when a user is selected in the 'Assigned to' field on the Incident table. I have created a 'Manager' field as read-only, and I've developed a Script Include along with an OnChange Client Script to achieve this functionality. However, I'm facing issues with fetching and displaying the manager's name upon selecting the user in the 'Assigned to' field.

Could someone please assist me with the correct implementation? Additionally, I would like to know if this is the best approach. Specifically, I am interested in knowing which method would require less coding while maintaining efficiency.

Thank you in advance for your assistance. 

 

 

5 REPLIES 5

Pratima Kalamka
Kilo Sage

Hello @Ashish Khairnar 

You can use script include and client script for that use case and I have tried and its works. Please try this let me know:

Script Include:

Client Callable

script:

var AutoPopulate_AssingedInfo = Class.create();
AutoPopulate_AssingedInfo.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getAssingedInfo: function()
{
	var sysIdOfAssinged=this.getParameter('sysparm_value');
	gs.log("sys_id",sysIdOfAssinged);

	var x=new GlideRecord('sys_user');
	x.addQuery('sys_id',sysIdOfAssinged);
	x.query();
	if(x.next())
	{
		gs.log("assinged to manager are "+x.manager);
		return x.manager+ ','+x.email;
	}
},
    type: 'AutoPopulate_AssingedInfo'
});

 

Client Script:

onchange-assigned_to

script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
var callerDetails=g_form.getValue('assigned_to');
var ga=new GlideAjax('AutoPopulate_AssingedInfo');
ga.addParam('sysparm_name','getAssingedInfo');
ga.addParam('sysparm_value',callerDetails);
ga.getXML(callback);

function callback(response)
{
	var answer= response.responseXML.documentElement.getAttribute('answer');
	//alert(answer);
	var test=answer.split(',');

g_from.setValue('u.manager',test[0]);
g_from.setValue('email',test[1]);
//g_form.setvalue('')
}
   //Type appropriate comment here, and begin script below
   
}

 

If my answer is helpful please mark it as helpful or correct!!