- 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 11:45 PM
Hi,
as you are using this in scoped app this won't work
gs.getUser().getDepartmentID()
so update code as below; query logged in user record and get the department value
Also the field from where you are calling is it in your 200 Upload Limit scope; I could see the script include is in that scope and accessible only from same scope;
If that user field is in global scope then it won't be able to call this script include as it is accessible only in same scope
var getMyDepartments1 = Class.create();
getMyDepartments1.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: '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:58 PM
Hi,
Thank you politely.
Do I need to create this script include in Global?
Regards,
- 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-24-2020 02:26 AM
Hi,
I worked it!
Thank you so much.
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2023 03:33 AM