- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2017 12:54 AM
I have variable name, User(user_id) and Line Manager(line_manager). Line manager should populated based on the user selected. Please suggest the catalog client script for this.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2017 02:17 AM
I would suggest use script include,
Use below code
Script include
var userDetails = Class.create();
userDetails .prototype = Object.extendsObject(AbstractAjaxProcessor, {
getManager: function() {
var gr=new GlideRecord("sys_user");
gr.addQuery("sys_id",this.getParameter('sysparam_id'));
gr.query();
gr.next();
if(gr.manager!=''){
return gr.manager.name;
}
else
{
return "blank";
}
},
type: 'userDetails '
});
Client Script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('userDetails');
ga.addParam('sysparm_name','getManager'); // pass script include function
ga.addParam('sysparam_id',newValue);
ga.getXML(Process);
}
function Process(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
g_form.setValue("man",answer); // man should be line manager variable name
}
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2017 12:59 AM
Hi Venkatesh,
Please write an onChange Catalog Client Script on change of the variable User as of the below screenshot. I believe you want to populate the selected User's Manager in the 'Line Manager' variable. Also I believe that both the variables are Reference type and referring User (sys_user) table.
I hope this helps.Please mark correct/helpful based on impact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2017 01:44 AM
I tried this code but manager name not changing while changing the user name. Both variables referring (sys_user) table only.
Sudhrithi is Venkatesh's Manager. When changing to A islam manager name remains same but islam's manger is not Sudhrithi(Islam's manager is Durai).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2017 01:59 AM
Hi Venkatesh,
Please try below code if it helps:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
var cos=g_form.getReference('user_id');
g_form.setValue('line_manager',cos.manager);
return;
}
var cos=g_form.getReference('user_id');
g_form.setValue('line_manager',cos.manager);
//Type appropriate comment here, and begin script below
}
This script is running perfectly for me with same scenario.
Regards,
Anjali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2017 02:16 AM
Try this script,
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading){
return;
}
if (newValue==''){
g_form.setValue('line_manager','');
}
else{
var user =g_form.getReference('user_id',fetchManager);
}
}
function fetchManager(){
g_form.setValue('line_manager',user.manager);
}