populate caller id manager name in the short description

showsid02
Tera Contributor

i have to populate caller id manager name in the short description field in incident using glide Ajax and script include.

 

Please provide the code for onchange CS and SI as well.

 

 

6 REPLIES 6

Harish Bainsla
Kilo Patron
Kilo Patron

hi please go through video you will have an idea 

https://youtu.be/4unHkSkkT70?si=Woor_kZULtfIb3wR

yesubabu Jonnal
Tera Contributor

SI-------------------

var Getusermngr = Class.create();
Getusermngr.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getusrmngr: function() {
var user_info = '';

var userid_value = this.getParameter('getif from your CS');
//Validating User manager
var user_rec = new GlideRecord('sys_user');
user_rec.addQuery('user_name', userid_value);
user_rec.query();
if(user_rec.next()){
user_info = user_rec.manager.DisplayValue()

}

return user_info;

},

CS--------------------------------------

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var ga = new GlideAjax('Getusermngr');
    ga.addParam('sysparm_name', 'getusrmngr');
    ga.addParam('userId', newValue);
    ga.getXMLAnswer(getResponse);
 
    function handleExceptionDurationValidationAjax(response) {
var result = response.responseXML.documentElement.getAttribute('answer');
if (result) {
g_form.setValue('your field', result, );
}
}
 
Please excuse for typo mistake  

Ankur Bawiskar
Tera Patron
Tera Patron

@showsid02 

It should be a simple task.

Did you go through GlideAjax documentation?

what did you start with and where are you stuck?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Mohan raj
Mega Sage

Hi @showsid02,

 

Script Include:

var TestingScript= Class.create();
TestingScript.prototype = Object.extendsObject(AbstractAjaxProcessor, {
populateFields : function(){
		var callerID = this.getParameter('sysparm_callerID');
		var user = new GlideRecord('sys_user');
		var result = {};
		if(user.get(callerID)){
			result.caller_id = user.name.toString();       // get full name
			result.manager = user.manager.name.toString(); // get manager full name
		}
		return JSON.stringify(result);
	},

    type: 'TestingScript'
});

 

Client Script

Type : Onchange 

Field : Caller

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

   //Type appropriate comment here, and begin script below
   var sd = g_form.getValue('short_description');
   var ga = new GlideAjax('TestingScript');
   ga.addParam('sysparm_name','populateFields');
   ga.addParam('sysparm_callerID',g_form.getValue('caller_id'));
   ga.getXML(callBack);
   function callBack(response){
	var answer = response.responseXML.documentElement.getAttribute('answer');
	var data = JSON.parse(answer);
	// adding the caller and manager in short description at last
	g_form.setValue('short_description',sd+'( Caller ID : '+data.caller_id+' and Manager : '+data.manager+')'); 

   }
   
}

 

 

If my response helps you to resolve the issue close the question by Accepting solution and hit thumb icon. From Correct answers others will get benefited in future.

Regards,

T Mohan.