- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2018 01:00 PM
Can some one give me the code for getting the logged in user department
I tried gs.getUser().getDepartmentID(); and getDepartmentID() none of them worked
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2018 07:55 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2018 01:44 PM
no luck with that 😞
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2018 07:20 AM
Hello,
Try below code to get department name:
var gr=new GlideRecord('sys_user');
gr.addQuery('sys_id',gs.getUserId());
gr.query();
if(gr.next())
{
var department=gr.department; // should be field name of department.
var dp=new GlideRecord('cmn_department'); // this should be department table name
dp.addQuery('sys_id',department);
dp.query();
if(dp.next())
{
var departmentName=dp.name;
gs.addInfoMessage(departmentName);
gs.info("Department Name:"+departmentName);
}
}
Note: Please hit like, helpful or correct depending on the impact of the response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2018 07:27 AM
Let's take a step back here for a moment. A Workflow runs behind the scenes and there is no relation to a logged-in user. It just makes no sense to get the Department of a logged-in user in this context.
What exactly are you trying o do? Is the Workflow running on a Catalog Item or some other table? You should be retrieving the Department from a reference variable or field on a table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2018 07:55 AM
yep its running on Cat Item and thanks for responding . below code fixed my problem.
obj.u_department = current.opened_by.department;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2018 07:55 AM
obj.u_department = current.opened_by.department; is the fix