Skip approval when requested for manager is raising the request

piyushnector
Tera Contributor

Hi All,

 

I was doing one development but there is some issue with the approval.

On catalog Item, there are a few variables

1- Opened By [opened_by]

2- For Whom? [for_whom]

3- etc...

I need to skip the approval in workflow following the below condition - 

No Approval Required When:

User in the variable "Opened by" = "For Whom?"

OR

Manager of User in the variable "For Whom?" = "Opened By" 

 

Regards,

Piyush

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use Workflow IF Activity

-> output of yes means approval is required

-> output of no means skip approval

Something like this

answer = ifScript();

function ifScript() {
	
	var gr = new GlideRecord("sys_user");
	if(gr.get(current.variables.for_whom)){
		var manager = gr.manager.toString();
		var openedUser = current.variables.opened_by.toString();
		if(openedUser == current.variables.for_whom.toString() || openedUser == manager)
			return 'no';
		else
			return 'yes';
	}
}

Regards
Ankur

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

View solution in original post

3 REPLIES 3

Dan H
Tera Guru

Hi Piyush,

You need to modify the workflow that is being used in the catalog item.

Add an If activity before the approval.

Script will look something like:

  answer = approvalNeeded();

	var user = current.variables.for_whom; //Is this a sys id? / Reference field?
	var userRecord = new GlideRecord('sys_user');
	userRecord.get(user); 
	var manager = userRecord.manager.toString();

  function approvalNeeded() {
     if (current.variables.opened_by.toString() == current.variables.for_whom.toString() || current.variables.opened_by.toString() == manager) {
        return 'no';
     }
     return 'yes';
  }

 

Workflow will look something like:

find_real_file.png

 

PPlease mark answer as helpful/correct based on impact

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use Workflow IF Activity

-> output of yes means approval is required

-> output of no means skip approval

Something like this

answer = ifScript();

function ifScript() {
	
	var gr = new GlideRecord("sys_user");
	if(gr.get(current.variables.for_whom)){
		var manager = gr.manager.toString();
		var openedUser = current.variables.opened_by.toString();
		if(openedUser == current.variables.for_whom.toString() || openedUser == manager)
			return 'no';
		else
			return 'yes';
	}
}

Regards
Ankur

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

I want to add this to all my workflows which ever is having manager approval in our instance. 

If opened by is a manager of requested for then the manager Approval should be skipped.

 

 

is there a simplest way to do that?