Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions Server-Side Components/Script Includes/LoggedInUser/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This Script Include filters user records so that only users from the same country as the logged-in user are shown.
It can be used as a Reference Qualifier for fields like Caller in forms such as Incident or Request.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
var getLoggedUserCountryLocs = Class.create();
getLoggedUserCountryLocs.prototype = {
initialize: function() {
},
getCountry: function() {

gs.addInfoMessage(gs.getUserID());
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', gs.getUserID());
gr.query();
if (gr.next()) {
var loc = gr.location;
var country = gr.location.country;
}


var grUsers = new GlideRecord('cmn_location');

grUsers.addQuery('country', country);
grUsers.query();
var locs = "";
while (grUsers.next()) {

locs += grUsers.sys_id + ",";
}
gs.addInfoMessage(locs);
var users = new GlideRecord('sys_user');
users.addQuery('location', 'IN', locs);
users.query();

var l = "";
while (users.next()) {

l += users.sys_id + ",";

}
return 'sys_idIN' + l;
},

type: 'getLoggedUserCountryLocs'
};
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