Print current loggedin user manager name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2025 04:53 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2025 05:05 AM
Hello @Shubham_verma,
Please try below solution:
Display Business Rule:
(function executeRule(current, previous /*null when async*/) {
// Initialize g_scratchpad object if not already done
g_scratchpad = g_scratchpad || {};
// Get the current logged-in user's manager
var user = gs.getUser();
var manager = user.getRecord().getDisplayValue('manager');
// Set the manager name in g_scratchpad
if (manager) {
g_scratchpad.manager_name = manager;
} else {
g_scratchpad.manager_name = "No manager assigned";
}
gs.info("Manager name set in g_scratchpad: " + g_scratchpad.manager_name);
})(current, previous);
Client Script:
function onLoad() {
// Check if the manager name is available
if (g_scratchpad.manager_name) {
alert("Manager Name: " + g_scratchpad.manager_name);
} else {
alert("Manager name not found.");
}
}
Please mark solution as helpful if it helps.
Thank you,
Vijay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2025 05:47 AM
It seems like that should work, but maybe it's a timing issue. A slightly longer display BR script with your client script will do the same:
(function executeRule(current, previous /*null when async*/) {
var usr = new GlideRecord('sys_user');
if (usr.get(gs.getUserID())) {
g_scratchpad.manager = usr.manager.name;
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2025 05:55 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2025 06:26 AM
Hi @Shubham_verma ,
Can you make sure that your BR is a display business rule.
Use Below code
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord("sys_user");
gr.get("sys_id",gs.getUserID());
g_scratchpad.mang = gr.manager.getDisplayValue();
})(current, previous);
If my response helped, then please accept the solution and hit thumbs up so that it benefits future reader as well.
Regards,
Rohit