- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2020 10:38 PM
Hi,
I want to set a person who belongs to the same department as the applicant's department.
But it returns an error..
What's wrong?
Script Include:
var getMyDepartments = Class.create();
getMyDepartments.prototype = {
initialize: function() {},
getDepartmentUsers: function() {
var usersList = "sys_idIN";
var grUser = new GlideRecord('sys_user');
grUser.addQuery('company', gs.getUser().getCompanyID());
grUser.addQuery('department', gs.getUser().getDepartmentID());
grUser.query();
while (grUser.next()) {
usersList = usersList + ',' + grUser.sys_id;
}
},
type: 'getMyDepartments'
};
variable Reference qualitifier:
System log:
Regards,
Solved! Go to Solution.
- Labels:
-
Script Debugger
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2020 12:27 AM
Hi,
you can create new one with some other name and keep accessible from as All application scope
var getMyDepartments2 = Class.create();
getMyDepartments2.prototype = {
initialize: function() {},
getDepartmentUsers: function() {
var userRec = new GlideRecord('sys_user');
userRec.get(gs.getUserID());
var department = userRec.getValue('department');
var usersList = [];
var grUser = new GlideRecord('sys_user');
grUser.addQuery('company', gs.getUser().getCompanyID());
grUser.addQuery('department', department);
grUser.query();
while(grUser.next()) {
usersList.push(grUser.getUniqueValue());
}
return 'sys_idIN' + usersList;
},
type: 'getMyDepartments2'
};
call it like this from ref qualifier:
javascript: new x_223778_upload_li.getMyDepartments2().getDepartmentUsers();
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
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-23-2020 10:45 PM
Hi,
are you running this in scoped application? also both the field and script include is in same scope
can you change the script include name to this getMyDepartments1 and update code as below
you were not returning the usersList from script include
var getMyDepartments1 = Class.create();
getMyDepartments1.prototype = {
initialize: function() {},
getDepartmentUsers: function() {
var usersList = [];
var grUser = new GlideRecord('sys_user');
grUser.addQuery('company', gs.getUser().getCompanyID());
grUser.addQuery('department', gs.getUser().getDepartmentID());
grUser.query();
while(grUser.next()) {
usersList.push(grUser.getUniqueValue());
}
return 'sys_idIN' + usersList;
},
type: 'getMyDepartments1'
};
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
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-23-2020 11:01 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2020 11:07 PM
Hi,
you should remove client callable checkbox;
also use this javascript: new getMyDepartments1().getDepartmentUsers();
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
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-23-2020 11:11 PM