Is there a job that removes the Manager Hub user role if someone is no longer a manager?

Community Alums
Not applicable

The Manager Hub user role gets assigned through the following scheduled job: Add Manager Hub user role The role assigned is: sn_mh.manager_hub_user If someone is no longer a manager, how does the role get removed?

1 ACCEPTED SOLUTION

Sumanth16
Kilo Patron

Hi @Community Alums ,

 

1. You can achieve this using flow designer without writing the script. [Highly recommended]

Documentation: https://docs.servicenow.com/bundle/quebec-servicenow-platform/page/administer/flow-designer/concept/...

2. Create an After Update Business rule on the Group table.

When to Run: Manager [changes]

Advance:

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var gr = new GlideRecord("sys_user_has_role");
	gr.addQuery("user", previous.manager);
	gr.addQuery("role.name", "approver_user");
         gr.setLimit(1);
	gr.query();
	if (gr.next()) {
		gr.deleteRecord();
	}

})(current, previous);

 

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda

View solution in original post

2 REPLIES 2

Amit Pandey
Kilo Sage

Hi @Community Alums 

 

You can manually remove the role. If the role is assigned to a certain group, you need to exclude the user from that group. Also, you can create a flow designer, scheduled job to do it automatically.

 

Regards,

Amit

Sumanth16
Kilo Patron

Hi @Community Alums ,

 

1. You can achieve this using flow designer without writing the script. [Highly recommended]

Documentation: https://docs.servicenow.com/bundle/quebec-servicenow-platform/page/administer/flow-designer/concept/...

2. Create an After Update Business rule on the Group table.

When to Run: Manager [changes]

Advance:

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var gr = new GlideRecord("sys_user_has_role");
	gr.addQuery("user", previous.manager);
	gr.addQuery("role.name", "approver_user");
         gr.setLimit(1);
	gr.query();
	if (gr.next()) {
		gr.deleteRecord();
	}

})(current, previous);

 

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda