- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2023 12:44 AM
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'
});
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2023 01:15 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2023 01:14 AM
@Ankur Bawiskar @Community Alums : Can anyone help me with the above script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2023 01:15 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2023 01:18 AM
@Ankit Rawat : Thanks a lot, It works, Have a Great day.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2023 01:20 AM
Your Welcome
Regards,
Ankit