Skip to content

Commit 6ec1f27

Browse files
User Access Test using background script (#2573)
* userAccessTester.js * README.md
1 parent e97d8ec commit 6ec1f27

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Simple background script to test user access to records and fields by impersonating different users.
2+
3+
## What it does
4+
5+
- Impersonates a specified user
6+
- Tests access to a specific record
7+
- Checks visibility of configured fields
8+
- Returns to original user context
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
var CONFIG = {
2+
tableName: 'incident',
3+
recordSysId: 'your_record_sys_id_here',
4+
userToImpersonate: 'user_sys_id_here',
5+
fieldsToTest: ['number', 'short_description', 'priority', 'assignment_group']
6+
};
7+
8+
var originalUserID = gs.getUserID();
9+
var impersonator = new GlideImpersonate();
10+
11+
gs.print("Original user: " + gs.getUser().getDisplayName());
12+
13+
impersonator.impersonate(CONFIG.userToImpersonate);
14+
gs.print("Now impersonating: " + gs.getUser().getDisplayName());
15+
16+
var gr = new GlideRecordSecure(CONFIG.tableName);
17+
if (gr.get(CONFIG.recordSysId)) {
18+
gs.print("Record accessible: " + gr.getDisplayValue());
19+
20+
for (var i = 0; i < CONFIG.fieldsToTest.length; i++) {
21+
var field = CONFIG.fieldsToTest[i];
22+
var value = gr.getDisplayValue(field);
23+
gs.print("Field '" + field + "': " + (value || 'Empty/No access'));
24+
}
25+
} else {
26+
gs.print("Record not found or not accessible");
27+
}
28+
29+
impersonator.impersonate(originalUserID);
30+
gs.print("Back to original user: " + gs.getUser().getDisplayName());

0 commit comments

Comments
 (0)