Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Filter Users by Department

Overview
This Script Include returns users whose department is the same as the currently logged-in user’s department.
It can be used to filter the Caller field or any user reference field to show only users from the same department.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an example of what the reference qualifier will look like? This would make it easier for other users to use.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var getSameDeptUsers = Class.create();
getSameDeptUsers.prototype = {
initialize: function() {},
getSameDept: function() {
var user = gs.getUser().getDepartmentID();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var user is not a good name for the Department. Perhaps userDepartment?

var d = new GlideRecord('sys_user');
d.addQuery('department', user);
d.query();

var str = "";
while (d.next()) {
str = str + "," + d.sys_id;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first value in the array will be empty. Perhaps you can use Array push? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push

}
return 'sys_idIN' + str;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you then can include the array to string


},

type: 'getSameDeptUsers'
};
Loading