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

SanjivMeher
Kilo Patron
Kilo Patron

Hi Becky,



I would also suggest the same. Add an activity with worknotes with text in a workflow Run Script,



current.work_notes = 'Request has been auto-approved, since request is submitted by manager';



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

The issue is that when a user submits a ticket, the workflow auto approves instead of sending the request to the manager.



When a user submits the ticket - approval by manager is required.


When a manager submits a ticket for a user - approval by manager is automated.


Hi Becky,



in Service Request, there is a Request which is parent. And under a Request, a requested item is created.



If your Approval is linked to a Request, you will have to query the RITM to get your cost center value.



If your Approval is linked to a Requested Item, condition should be


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


  answer = 'no';



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

I'm still having issues with this.



I have an IF condition set up at the beginning of the workflow it contains:


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


//


// For example,


//


//     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';


//     }



path from Yes goes to a run script action that contains:


current.work_notes = "Manager requesting, No approvals are required";


current.update();



path from No goes to run an approval action that contains:


// Set the variable 'answer' to a comma-separated list of user ids and/or group ids or an array of user/group ids to add as approvers.


//


// For example:


//             answer = [];


//             answer.push('id1');


//             answer.push('id2');


answer = [];


answer.push(current.variables.requested_for.manager);



The issue is the "NO" path isn't being considered.



When I put in a ticket impersonating my boss, the workflow processes as I'm expecting, the ticket auto approves.


When I put in a ticket as myself, the workflow follows the wrong path, it auto approves instead of going to my manager for approval.



What's not right?