How to Automate Approvals in Service Catalog workflows, when request is submitted by User's Manager or by Cost Center owner?

becks_kirk
Tera Contributor

Original Question:

We've recently decided that if a Manager opens a ticket on behalf of   a user who reports to them in ServiceNow, the approval will be automatic. Managers hate having to do approvals for tickets they submit for their resources, they often forget that after they submit the ticket, they have to go to another area of SN to do the approval.

Anyway we've got a way to do the approval automatically that is pasted below. What I need now, is the ticket to save a simple note to the activity section of the ticket. With out this, auditors are going to flip and our Asset Management team questions if the SR was actually approved financially speaking.

This runs if a manager is submitting a SR on behalf of their resource:

answer = 'yes';

if (current.variables.requested_for.manager == current.variables.cost_center.manager || current.variables.requested_for.manager == current.variables.cost_center.u_alternate_approver)

  answer = 'no';

Does my issue make sense? Greatly appreciate if anyone can guide me on this one!

I also attached a picture of where the system shows no 'approval' because it was auto approved upon submission, and no notes in the 'activity' section.

Partial Solution:


From your If Activity for "No" condition, Add a transition to a new   run script activity and specify this code in it.

  1. current.work_notes = "Manager requesting, No approvals are required";
  2. current.update();

Outstanding Issue:

So once I began testing some more, I realized, the script started to override the approval process when the user submits a ticket on their own. There has to be something to keep the approval from generating automatically when the user submits a ticket that requires routing to their manager. What kind of logic to I need to set up?

7 REPLIES 7

Hi Becky,



You seems to have commented your code. uncomment and try



// This script needs to set answer to 'yes' or 'no' to indicate the state of the activity.


//


// For example,


//


// Remove comments from below sections


//   answer = ifScript();


//


//   function ifScript() {


//   if (current.request.opened_by.manager == current.variables.cost_center.manager || current.request.opened_by.manager == current.variables.cost_center.u_alternate_approver)


  answer = 'yes';


// }





Please mark this response as correct or helpful if it assisted you with your question.

I removed them as you marked it, now when I process the request as the manager and approval task is generated instead of the ticket automatically approving.


Lets add few debugging statement.Can you add the below in your if script and let me know what do you see in your logs after submitting a new request.




answer = ifScript();


function ifScript() {


gs.log('++++++++++++++current.request.opened_by.manager ========='+current.request.opened_by.manager);


gs.log('++++++++++++++current.variables.cost_center.manager ========='+current.variables.cost_center.manager);


gs.log('++++++++++++++current.variables.cost_center.u_alternate_approver ========='+current.variables.cost_center.u_alternate_approver);



if (current.request.opened_by.manager == current.variables.cost_center.manager || current.request.opened_by.manager == current.variables.cost_center.u_alternate_approver)


  answer = 'yes';


}



Please mark this response as correct or helpful if it assisted you with your question.