How to Assign the Requester's Manager to a Request Item (RITM) for Approval.

humblecommitted
Kilo Guru

Hello Community,

I tried following this forum but it didn't work for me:

How to add Manager Approval in workflow based on custom item variable

So what I want to do is for the manager field of a request, I would like that manager that is filled out in that field to be the RITM is assigned to for approval:

I have supplied the following screen shots below:

Here is the Request form:

3.jpg

Here is the name of the manager field:

3.1.jpg

Here is where I want to populate the "Assigned to" field to what was populated in the managers field from the request form:

3.2.jpg

Here is the work flow associated with the Request:

1.jpg

I tried putting in this code to have it transfer the manager variable to the "Assigned to" field of the request:

2.jpg

Please let me know what I am doing wrong.   Any help would be greatly appreciated.

1 ACCEPTED SOLUTION

Hello Everyone,



So I was able to resolve this by doing the following:



I created the following items on the work flow:


1.jpg


The script for the Run Script:



assigntomanager();


function assigntomanager() {


gs.log("Assigning Request Item to Requester's Manager");


//var assigntomanager = new GlideRecord('sc_rq'); no need to make glideRecord, your workflow is on sc_req_item table so current refers to current record of //sc_req_item itself



//assigntomanager.current.assigned_to = current.variables.manager; // no need to add assigntomanager before current object, wrong syntax


current.assigned_to = current.variables.manager ; // correct syntax


}


3.jpg


and I had to use a script since the approver of the request could change and the variable field was dynamic.   The Advance script for the Approval - User:


// 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:


//gs.log("starting approval script");


            answer = [];


//             answer.push('current.variables.manager');


          answer.push(current.variables.manager);






//answer = current.variables.manager;




//gs.log(" variable is " + current.variables.manager + " answer is " + answer);


2.jpg



now the manager of the requested_for user will be set as the approve on the Request Item (RITM).



Thank you all for your assistance.


View solution in original post

8 REPLIES 8

Deepak Ingale1
Mega Sage

Hi Orlando,



You want to set the RITM "Assigned To" field to the manager variable on the form.



What you are trying in workflow is to trigger an approval for manager using approval group activity. First, for user approval (manager is user), you should use "Approaval user" activity and not "approval group". Second, if you want "assigned to" field on RITM to be same as manager variable, then you should do it via run script activity avaiable in the workflow.



Add the run script activity in your workflow at the appropriate place where you want assigned to field to be populated. Once done write down below line in script section which will set assigned to field to the manager variable on the form



current.assigned_to = current.variables.manager // I assume manager is the name of your variable.


Hello Deepak,



If i were to script it would it be something along the lines of



assigntomanager();


function assigntomanager() {


gs.log("Assigning Request Item to Requester's Manager");


var assigntomanager = new GlideRecord('sc_rq');



assigntomanager.current.assigned_to = current.variables.manager;


}


assigntomanager();


function assigntomanager() {


gs.log("Assigning Request Item to Requester's Manager");


//var assigntomanager = new GlideRecord('sc_rq'); no need to make glideRecord, your workflow is on sc_req_item table so current refers to current record of //sc_req_item itself



//assigntomanager.current.assigned_to = current.variables.manager; // no need to add assigntomanager before current object, wrong syntax


current.assigned_to = current.variables.manager ; // correct syntax


}


Hello Deepak,



That script worked and thanks for taking the time to explain and break it down for me.   I understand a lot more about work flows for items now.  



However I am left with one problem now.   The request item doesnt wait for the manager to approve it, but instead completes the whole workflow as seen in the image below.   Should I put in a wait condition?



Thanks in advance


1.jpg