- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2022 09:52 AM
name & approver Variable are Reference field from sys_user.
how can I get All Department head name as approver for choice onChange client Script?
Here I teste GlideAjax but i get only one Approver but i can not get other Department Head.
var Print_Approver = Class.create();
Print_Approver.prototype = Object.extendsObject(AbstractAjaxProcessor, {
ApproverAjax: function() {
var grUser = new GlideRecord('sys_user');
var userSysID = this.getParameter('sysparm_Test1');
grUser.addQuery('sys_id', userSysID);
grUser.query();
while (grUser.next()) {
return grUser.department.dept_head.getValue('sys_id');
}
},
type: 'Print_Approver'
});
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('Print_approver');
ga.addParam('sysparm_name', 'ApproverAjax');
ga.addParam('sysparm_Test1', g_form.getValue('name'));
ga.getXML(TestCallBack);
function TestCallBack(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
g_form.setValue('approver',answer);
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2022 10:38 AM
hello
you want to return the head of the department for the selected name in the name field right ?
is that your requirement ?
if yes what you have done is correct .
but can you explain in detail about this below statement?
but i get only one Approver but i can not get other Department Head.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2022 10:38 AM
hello
you want to return the head of the department for the selected name in the name field right ?
is that your requirement ?
if yes what you have done is correct .
but can you explain in detail about this below statement?
but i get only one Approver but i can not get other Department Head.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2022 11:50 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2022 12:26 AM
then try this you need to create an array and push all sys_ids and then return that array as our are expecting multiple values
var Print_Approver = Class.create();
Print_Approver.prototype = Object.extendsObject(AbstractAjaxProcessor, {
ApproverAjax: function() {
var arr=[];
var userSysID = this.getParameter('sysparm_Test1');
var grUser = new GlideRecord('sys_user');
grUser.addQuery('sys_id', userSysID);
grUser.query();
if (grUser.next()) {
var gr = new GlideRecord('sys_user');
gr.addQuery('department.dept_head',grUser.department.dept_head);
gr.query();
while(gr.next())
{
arr.push( gr.department.dept_head.toString());
}
}
return "sys_idIN"+arr;
},
type: 'Print_Approver'
});
MARK THIS ANSWER CORRECT IF IT HELPS YOU
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2022 10:39 AM
Hi
the reason for the current behavior is the following code. Here you already return after the first loop:
while (grUser.next()) {
return grUser.department.dept_head.getValue('sys_id');'
}
Instead you have to collect all Sys IDs and return after the looping.
Instead write:
var arrSysIDs = [];
while (grUser.next()) {
arrSysIDs.push(grUser.department.dept_head.getValue('sys_id'));
}
return arrSysIDs.join(',');
On client side you have to split the returned string to get all Sys IDs as single values.
Maik