|
1 | | -var impersonatorSysId = 'zane.sulikowski'; //Replace it with the userID of userfor whom we need to check impersonation details |
| 1 | +var impersonatorUserID = 'zane.sulikowski'; //Replace it with the user ID of user for whom we need to check impersonation details |
2 | 2 |
|
3 | | -var checkUserId = new GlideRecord('sys_user'); |
4 | | -if (checkUserId.get('user_name', impersonatorSysId)) { |
| 3 | +var isUserPresent = new GlideRecord('sys_user'); |
| 4 | +if (isUserPresent.get('user_name', impersonatorUserID)) { |
5 | 5 |
|
6 | | - var eventsGR = new GlideRecord('sysevent'); |
7 | | - eventsGR.addEncodedQuery("name=impersonation.start^ORname=impersonation.end^parm1=" + impersonatorSysId + "^sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()"); |
8 | | - eventsGR.orderBy('sys_created_on'); |
9 | | - eventsGR.query(); |
| 6 | + var queryEvents = new GlideRecord('sysevent'); |
| 7 | + queryEvents.addEncodedQuery("name=impersonation.start^ORname=impersonation.end^parm1=" + impersonatorUserID + "^sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()"); |
| 8 | + queryEvents.orderBy('sys_created_on'); |
| 9 | + queryEvents.query(); |
10 | 10 |
|
11 | 11 | //This object will hold all events grouped by impersonated user which is in parm2 |
12 | 12 | var userEvents = {}; |
13 | 13 |
|
14 | | - while (eventsGR.next()) { |
15 | | - var impersonatedId = eventsGR.getValue('parm2'); |
| 14 | + while (queryEvents.next()) { |
| 15 | + var impersonatedId = queryEvents.getValue('parm2'); |
16 | 16 | if (!userEvents[impersonatedId]) |
17 | 17 | userEvents[impersonatedId] = []; |
18 | 18 | userEvents[impersonatedId].push({ |
19 | | - name: eventsGR.getValue('name'), |
20 | | - time: eventsGR.getValue('sys_created_on') |
| 19 | + name: queryEvents.getValue('name'), |
| 20 | + time: queryEvents.getValue('sys_created_on') |
21 | 21 | }); |
22 | 22 | } |
23 | 23 |
|
@@ -55,6 +55,6 @@ for (var userId in userEvents) { |
55 | 55 | var minutes = Math.floor((totalSeconds % 3600) / 60); |
56 | 56 | var seconds = Math.floor(totalSeconds % 60); |
57 | 57 |
|
58 | | - gs.info(impersonatorSysId + " impersonated User: " + getUserName(userId) + |
| 58 | + gs.info(impersonatorUserID + " impersonated User: " + getUserName(userId) + |
59 | 59 | " - Total Duration of impersonation is : " + hours + "hrs " + minutes + "min " + seconds + "sec (" + totalSeconds + "sec)"); |
60 | 60 | } |
0 commit comments