Skip to content

Commit b115678

Browse files
Merge pull request #6 from NavyasreeBolleboyana/patch-20
Create LoggedInUsersCountries.js
2 parents 3a329a2 + 582252d commit b115678

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
var getLoggedUserCountryLocs = Class.create();
2+
getLoggedUserCountryLocs.prototype = {
3+
initialize: function() {
4+
},
5+
getCountry: function() {
6+
7+
gs.addInfoMessage(gs.getUserID());
8+
var gr = new GlideRecord('sys_user');
9+
gr.addQuery('sys_id', gs.getUserID());
10+
gr.query();
11+
if (gr.next()) {
12+
var loc = gr.location;
13+
var country = gr.location.country;
14+
}
15+
16+
17+
var grUsers = new GlideRecord('cmn_location');
18+
19+
grUsers.addQuery('country', country);
20+
grUsers.query();
21+
var locs = "";
22+
while (grUsers.next()) {
23+
24+
locs += grUsers.sys_id + ",";
25+
}
26+
gs.addInfoMessage(locs);
27+
var users = new GlideRecord('sys_user');
28+
users.addQuery('location', 'IN', locs);
29+
users.query();
30+
31+
var l = "";
32+
while (users.next()) {
33+
34+
l += users.sys_id + ",";
35+
36+
}
37+
return 'sys_idIN' + l;
38+
},
39+
40+
type: 'getLoggedUserCountryLocs'
41+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# getLoggedUserCountryLocs Script Include
2+
3+
## Overview
4+
5+
The **getLoggedUserCountryLocs** Script Include is a custom ServiceNow utility that retrieves all users who belong to the same **country** as the **currently logged-in user**.
6+
7+
It performs this by:
8+
1. Fetching the logged-in user's country (based on their location record).
9+
2. Identifying all location records that belong to the same country.
10+
3. Gathering all users assigned to those locations.
11+
4. Returning a GlideRecord-encoded query string (`sys_idIN...`) that can be used to filter or query other records.

0 commit comments

Comments
 (0)