Skip to content

Commit b2cbd7f

Browse files
authored
Script Include to get current user information (ServiceNowDevProgram#731)
* Created a script include to get the current user information. * Description for "Get Current User Information" script include
1 parent f8f070f commit b2cbd7f

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var GetCurrentUserInfo = Class.create();
2+
GetCurrentUserInfo.prototype = {
3+
initialize: function() {},
4+
5+
getCurrentUserInfo: function() {
6+
var currentUser = gs.getUser(); //This will give the reference to current user object.
7+
var userId = currentUser.getName();
8+
var firstName = currentUser.getFirstName();
9+
var lastName = currentUser.getLastName();
10+
var email = currentUser.getEmail();
11+
var sysId = currentUser.getID();
12+
var roles = currentUser.getRoles();
13+
14+
return {
15+
userId: userId,
16+
firstName: firstName,
17+
lastName: lastName,
18+
email: email,
19+
roles: roles,
20+
sysId: sysId
21+
};
22+
},
23+
type: 'GetCurrentUserInfo'
24+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Get Current User Information
2+
We frequently need essential current user information such as userId, name, sysId, email, and roles on the client side. To streamline this process, I've developed a Script Include that can be invoked directly from the client side.
3+
This Script Include fetches and provides an object encapsulating the current user's userId, firstName, lastName, email, roles, and sysId for easy access.

0 commit comments

Comments
 (0)