while triggering Manger Approval, If the user manager is Inactive or empty needs to create SCtask

praveen47
Tera Contributor

Hi Everyone, 

 

I have a requirement like

 

In workflow we are triggering Manager approval, for some users manager is empty or active false. Handling this situation we decided to check If the Manager is Active or not. If active it goes to manger approval, manger is Inactive or empty need to create one Sctask. 

 

For achiving this I have added If condtion before Manger approval to check Active or not.

 

I have added the below script in the If Condition:

// replace with the sys_id of the user whose manager you want to check
answer = ifScript();
function ifScript() {  
var userSysId = current.requested_for;
var user = new GlideRecord('sys_user');   
if (user.get(userSysId)) {        
var manager = new GlideRecord('sys_user');        
if (manager.get(user.manager)) {            
if (manager.active == 'true') {                
return 'yes';            
}            
return 'no';        
}   
 }
 }

 

This script is not checking when the user manger is Active or not, it is working only user manager field is empty.

 

Can anyone help me on this 

 

praveen47_0-1678679483554.png

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@praveen47 

try this

no need to query when you can directly dot walk

// replace with the sys_id of the user whose manager you want to check
answer = ifScript();

function ifScript() {  

	if(current.requested_for.manager.active.toString() == 'false' || current.requested_for.manager.nil())
		return 'no';
	else
		return 'yes';

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@praveen47 

try this

no need to query when you can directly dot walk

// replace with the sys_id of the user whose manager you want to check
answer = ifScript();

function ifScript() {  

	if(current.requested_for.manager.active.toString() == 'false' || current.requested_for.manager.nil())
		return 'no';
	else
		return 'yes';

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader