How to auto populate manager email id based on requested for variable using glideAjax

Aparna Gurav
Tera Contributor

Hello Team, 

 

Need your help,

I want to populate Manager's name and email address automatically by utilizing the "requested for" variable

Although I have created a client script and script include, it is not functioning as expected. Currently, it only populates the Manager's name and not their email address. If anyone has any suggestions, please let me know if there's anything

 

Client script

 

function onChange(control, oldValue, newValue, isLoading) {

if (newValue != '') {
var ga = new GlideAjax('SPR_Line');
ga.addParam('sysparm_name', 'getManagerAndEmail'); //sysparm_name is reserved for the name of the script include function to call
ga.addParam('sysparm_userId', g_form.getValue('requested_for'));
ga.getXML(clientCallback); //Use getXML rather than getXMLWait. Input is your callback function
}

function clientCallback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer"); //Get answer from server

if(answer){
var data = JSON.parse(answer);
}
//Do something with answer
g_form.setValue('manager', data.manager);
g_form.setValue('email', data.email);
}
}

 

Script include

 

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

getManagerAndEmail: function(){
var userID = this.getParameter('sysparm_userId');
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', userID);
gr.query();
if(gr.next()){
var userObj = {
email: gr.manager.email.toString(),
manager: gr.manager.toString()


};
return JSON.stringify(userObj);
}


},

type: 'SPR_Line'
});

 

AparnaGurav_0-1682581482198.png

 

AparnaGurav_1-1682581482223.png

 

 

1 ACCEPTED SOLUTION

Ankit Rawat
Giga Guru

Hi @Aparna Gurav ,

 

Change the type of Line Manager Email Address Variable. It is not populating because of the Reference type of Variable.

 

There is a variable type Email, use this type of variable.

 

Please mark this helpful and accept my solution if it helps.

 

Regards 

Ankit 

View solution in original post

4 REPLIES 4

Aparna Gurav
Tera Contributor

@Ankur Bawiskar @Community Alums : Can anyone help me with the above script?

Ankit Rawat
Giga Guru

Hi @Aparna Gurav ,

 

Change the type of Line Manager Email Address Variable. It is not populating because of the Reference type of Variable.

 

There is a variable type Email, use this type of variable.

 

Please mark this helpful and accept my solution if it helps.

 

Regards 

Ankit 

@Ankit Rawat : Thanks a lot, It works, Have a Great day.

Your Welcome

 

Regards,

Ankit