Populate Manager variable based on selection of User variable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
I'm working on a catalog item that has two variables
1. User -> Reference to sys_user table
2. Manager -> Select Box
The requirement is when a user is selected then Managers select Box should be populated with the Manager(s) of that user.
Some Users may have the same display name. example: three users named Abel, but they have different managers. Therefore, I want to populate all three users managers on the Manager Variable. I tried but null value is passing onto the client side however on server side I'm getting all the managers. Could anyone please guide me where I did wrong.
Server Side Script:
var fetchManager = Class.create();
fetchManager.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getName: function() {
var users = this.getParameter('sysparm_user');
var nam = '';
var grName = new GlideRecord('sys_user');
if (grName.get(users)) {
nam = grName.getDisplayValue();
}
var result = [];
var gr = new GlideRecord('sys_user');
gr.addQuery('name', nam);
gr.addNotNullQuery('manager');
gr.query();
while (gr.next()) {
var managerGr = gr.manager.getRefRecord();
if (managerGr) {
result.push({
label: managerGr.getDisplayValue().toString(),
value: managerGr.getDisplayValue().toString()
});
}
}
gs.info("List of Managers" + JSON.stringify(result));
return JSON.stringify(result);
},
type: 'fetchManager'
});
Client Side Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
} //Type appropriate comment here, and begin script below
var ga = new GlideAjax('fetchManager');
ga.addParam('sysparm_name', 'getName');
ga.addParam('sysparm_user', newValue);
ga.getXMLAnswer(function(answer) {
alert(answer);
if (!answer) {
g_form.clearOptions('managers');
return;
}
var accounts = JSON.parse(answer);
alert(accounts);
g_form.clearOptions('managers');
g_form.addOption('managers', '', 'select manager', '--Select Manager--');
for (var i = 0; i < accounts.length; i++) {
alert(accounts[i].label);
g_form.addOption('managers', accounts[i].value, accounts[i].label);
}
});
}
0 REPLIES 0