- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2016 09:18 AM
Hi All,
I wanted to fetch employee number of logged in user using UI Action script. Can please anyone suggest !
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2016 11:37 AM
Because your UI Action is client-side, you could use Session Client Data as explained in this blog post - Two ways to Reduce Client Side lookups
Or, as kalai mentioned in that blog post, a display Business Rule to add the Employee Number to the scratchpad - Client Script Best Practices - ServiceNow Wiki
Your Business Rule could look like:
Table: whatever table the UI Action is on
Advanced: checked
When: Display
Script:
(function executeRule(current, previous /*null when async*/) {
//add the Employee Number to the scratchpad
var gr = new GlideRecord("sys_user");
if (gr.get(gs.getUserID().toString())){
g_scratchpad.u_employee_number = gr.getValue("employee_number");
}
})(current, previous);
And then you should be able to access the value in your UI Action with g_scratchpad.u_employee_number.
NOTE: I modified the Business Rule to ensure compatibility with all versions of the platform.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2016 09:26 AM
There are predefined functions to get userID or sys id of the logged in user
More info:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2016 09:26 AM
Use this line in your UI action script to get the logged in user's employee number
gs.getUser().getRecord().getValue("employee_number");

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2016 09:30 AM
Works in which release?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2016 09:47 AM
Works in G, H. Did not test on Fuji