Print current loggedin user manager name

Shubham_verma
Tera Contributor

Hi,

 

I am not able to print current logged in user manager name using g_scratchpad for client script & business rule.

How can I achieve it?

Thanks in advance!

4 REPLIES 4

VIJAY YACHAM1
Tera Contributor

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

Brad Bowman
Kilo Patron
Kilo Patron

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);

 

J Siva
Tera Sage

Hi @Shubham_verma 

Use the below script in your Display business rule.

Screenshot_20250329-182233.png

 

Hope this helps.

Regards,

Siva

 

Rohit  Singh
Mega Sage

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