- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2025 06:12 AM
I am trying to build an offboarding catalog item that will look at the person being offboarded and if they are a manager, it will show a number of additional fields pertaining to direct reports and approvals the users might have currently. I know I need to validate if the user is a manager and I have found a script that will do it based off current user, but as that doesn't exactly pertain to this situation, I need to marry it with a onload script. I am not great at scripting and sadly this does not appear to be something mentioned before.
I assume the below snippet will work for determining if the target is a manager, just not sure how to adjust it to look at the reference field (In this case obu_employee_name). Do I just need to update the sys_user to the Reference Field?
var is_manager;
var gr = new GlideAggregate("sys_user");
gr.addQuery("manager",userID);
gr.query();
if(gr.getRowCount>0)
{
is_manager = "true";
}
else{
is_manager = "false";
}
My intent is to put the finalized script into a UI Policy.
Appreciate any assistance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2025 07:47 AM
Hi @ChrisWing ,
Few correction needs to be done in both Server Side and Client.
1. Make sure your script include is client callable, there is a check box in your script include.
getManagerInfo : function()
{
var gr = new GlideAggregate("sys_user");
gr.addQuery("manager",this.getParameter("sysparm_userid"));
gr.query();
if(gr.getRowCount>0)
{
return true;
}
else
{
return false;
}
},
Client Script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('ValidateManager');
ga.addParam('sysparm_name','getManagerInfo'); /// Add This line. This is a function within script include.
ga.addParam('sysparm_userid', g_form.getValue("obu_employee_name"));
ga.getXMLAnswer(Manager);
}
function Manager(answer) {
if((answer) == "true"){
g_form.setvisible('obu_Departing_Manager_Tasks',true);
} else {
g_form.setvisible('obu_Departing_Manager_Tasks',false);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2025 08:07 AM
your script include should be client callable
Script Include:
var ValidateManager = Class.create();
ValidateManager.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isManager: function() {
var is_manager;
var gr = new GlideAggregate("sys_user");
ga.addAggregate('COUNT');
ga.addQuery("manager", this.getParameter("sysparm_userid"));
ga.query();
if (ga.next()) {
var reporteeCount = ga.getAggregate('COUNT');
if (reporteeCount > 0) {
is_manager = "true";
} else {
is_manager = "false";
}
}
return is_manager;
},
type: 'ValidateManager'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('ValidateManager');
ga.addParam('sysparm_name', 'isManager');
ga.addParam('sysparm_userid', g_form.getValue("obu_employee_name"));
ga.getXMLAnswer(function(answer) {
if (answer.toString() == 'true') {
g_form.setvisible('obu_Departing_Manager_Tasks', true);
} else {
g_form.setvisible('obu_Departing_Manager_Tasks', false);
}
});
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2025 08:07 AM
your script include should be client callable
Script Include:
var ValidateManager = Class.create();
ValidateManager.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isManager: function() {
var is_manager;
var gr = new GlideAggregate("sys_user");
ga.addAggregate('COUNT');
ga.addQuery("manager", this.getParameter("sysparm_userid"));
ga.query();
if (ga.next()) {
var reporteeCount = ga.getAggregate('COUNT');
if (reporteeCount > 0) {
is_manager = "true";
} else {
is_manager = "false";
}
}
return is_manager;
},
type: 'ValidateManager'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('ValidateManager');
ga.addParam('sysparm_name', 'isManager');
ga.addParam('sysparm_userid', g_form.getValue("obu_employee_name"));
ga.getXMLAnswer(function(answer) {
if (answer.toString() == 'true') {
g_form.setvisible('obu_Departing_Manager_Tasks', true);
} else {
g_form.setvisible('obu_Departing_Manager_Tasks', false);
}
});
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2025 10:12 AM
Thanks @Rohit Singh and @Ankur Bawiskar for your assistance. Rohit and I spent some time on a call because it still wasn't quite worked however we ended up sorting it. I will post the finished code below for anyone else who is wondering how to achieve it. setVisible is case sensitive and was part of the issues we had. the other was "var gr", later in the code changed to "ga" which caused it not to function.
Script Include Used
var ManagerValidation = Class.create();
ManagerValidation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getManagerInfo : function()
{
var is_manager = '';
var ga = new GlideAggregate("sys_user");
ga.addAggregate('COUNT');
ga.addQuery("manager", this.getParameter("sysparm_userid"));
ga.query();
if (ga.next()) {
var reporteeCount = ga.getAggregate('COUNT');
if (reporteeCount > 0) {
is_manager = "true";
} else {
is_manager = "false";
}
}
return is_manager;
},
type: 'ManagerValidation'
});
Client Script Used
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('ManagerValidation');
ga.addParam('sysparm_name','getManagerInfo'); /// Add This line. This is a function within script include.
ga.addParam('sysparm_userid', g_form.getValue("obu_employee_name"));
ga.getXMLAnswer(function(answer) {
//g_form.addInfoMessage(answer);
if (answer.toString() == 'true') {
g_form.setVisible('obu_Departing_Manager_Tasks', true);
} else {
g_form.setVisible('obu_Departing_Manager_Tasks', false);
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2025 08:13 PM
I believe I also shared the correct solution.
The final script you shared resembles with the one I shared already.
If my response helped please mark it correct as well so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader