- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 07:06 AM
I am looking for a script where I want to send a approval request to a user and if user is not active it should go to the User's Manager.
The below script is not working
answer = [];
appr();
function appr() {
var ownerManager = [];
ownerManager = current.variables.v_role.u_owner.split(',');
var gr = new GlideRecord('sys_user');
gr.addQuery("sys_id",'IN',ownerManager);
gr.addActiveQuery();
gr.query();
while(gr.next()){
if (gr.active) {
answer.push(gr.user_name);
} else {
answer.push(gr.manager);
}
}
}
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 07:19 AM
Hi @Taaha M,
Assuming the ownerManager variable is filled correctly:
answer = [];
var ownerManager = [];
ownerManager = current.variables.v_role.u_owner.split(',');
var gr = new GlideRecord('sys_user');
gr.addQuery("sys_id","IN",ownerManager);
gr.query();
while(gr.next()){
if (gr.getValue('active')) {
answer.push(gr.getUniqueValue());
} else {
answer.push(gr.getValue('manager'));
}
}
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 07:20 AM - edited 10-04-2023 07:24 AM
If your u_owner field on the v_role referenced table is a list field, don't split it into an array before using it in the addQuery line as the value will be a comma-separated list of sys_ids. And you don't want to only return active records since you're checking for that in the returned records. Also, you need to push sys_ids to the answer array, not user_name, and when you push a sys_id to an array you need to either getValue or force it to a string or you will get an array of all the same sys_id (it pushes the memory location or something like that when it's not a string):
answer = [];
appr();
function appr() {
var gr = new GlideRecord('sys_user');
gr.addQuery("sys_id", 'IN', current.variables.v_role.u_owner);
gr.query();
while (gr.next()) {
if (gr.active == 'true') {
answer.push(gr.sys_id.toString());
} else {
answer.push(gr.manager.toString());
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 07:19 AM
Hi @Taaha M,
Assuming the ownerManager variable is filled correctly:
answer = [];
var ownerManager = [];
ownerManager = current.variables.v_role.u_owner.split(',');
var gr = new GlideRecord('sys_user');
gr.addQuery("sys_id","IN",ownerManager);
gr.query();
while(gr.next()){
if (gr.getValue('active')) {
answer.push(gr.getUniqueValue());
} else {
answer.push(gr.getValue('manager'));
}
}
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 07:20 AM - edited 10-04-2023 07:24 AM
If your u_owner field on the v_role referenced table is a list field, don't split it into an array before using it in the addQuery line as the value will be a comma-separated list of sys_ids. And you don't want to only return active records since you're checking for that in the returned records. Also, you need to push sys_ids to the answer array, not user_name, and when you push a sys_id to an array you need to either getValue or force it to a string or you will get an array of all the same sys_id (it pushes the memory location or something like that when it's not a string):
answer = [];
appr();
function appr() {
var gr = new GlideRecord('sys_user');
gr.addQuery("sys_id", 'IN', current.variables.v_role.u_owner);
gr.query();
while (gr.next()) {
if (gr.active == 'true') {
answer.push(gr.sys_id.toString());
} else {
answer.push(gr.manager.toString());
}
}
}