- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2023 04:15 AM
Thank you for your help.
I am working on a requirement that when an unauthorized user logs into the service portal and opens my_request, only the records of the department to which he/she belongs should be displayed.
We also need to determine if the department the user belongs to and the department registered in the record is a partial match.
I have tried to script an ACL for read, but am struggling to get the department name of the logged in user.
I can get the sys_id of the department with gs.getUser().getDepartmentID(), but I cannot bring the department name.
Please tell me how to get the name of the department from the logged in user's information.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2023 04:30 AM
Hi @N_Y_1014
As you are getting the sys_id of department & if I'm not wrong then you can glide record on "cmn_department" table on server side code
and get the Department name :
/* Will get the sys_id of dept*/
var deptSysid = gs.getUser().getDepartmentID();
var deptName;
/*Query on Department table */
var grDept = new GlideRecord('cmn_department');
grDept.addQuery('sys_id', deptSysid);
grDept.query();
if(grDept.next()){
deptName = grDept.name;
}
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2023 04:26 AM
query cmn_department table with that sysId and get the department name
var gr = new GlideRecord("cmn_department");
gr.addQuery("sys_id", gs.getUser().getDepartmentID());
gr.query();
if (gr.next()) {
var deptName = gr.name;
}
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
10-11-2023 04:30 AM
Hi @N_Y_1014
As you are getting the sys_id of department & if I'm not wrong then you can glide record on "cmn_department" table on server side code
and get the Department name :
/* Will get the sys_id of dept*/
var deptSysid = gs.getUser().getDepartmentID();
var deptName;
/*Query on Department table */
var grDept = new GlideRecord('cmn_department');
grDept.addQuery('sys_id', deptSysid);
grDept.query();
if(grDept.next()){
deptName = grDept.name;
}
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates