Create Second RITM in Workflow Activity

kevinthury
Tera Guru

Currently using ISTANBUL

Objective:   Create a second RITM under new REQ using script in Workflow.   This RITM would then trigger it's corresponding workflow.

Details:

We have a Catalog Item (New Provider) that allows our organization to ask for a onboarding staff to have specific permissions in a medical setting.   Training is also required for this new individual.   There is a separate Catalog Item used by our training team that allows them to track completion and communicate requirements for New Providers and other similar REQs (generally submitted via email).

Our goal is that when a new Provider is ordered from the Service Catalog, it's corresponding workflow will contain an activity that will generate a second RITM for the Training team under the same REQ.

I tried adding the following script to the New Provider Catalog Item in the "Delivery Plan Script field.   This didn't do anything at all which makes me wonder if I don't fully understand its purpose...or more likely, the script is faulty:

var reqItem = new GlideRecord('sc_req_item');

reqItem.initialize();

reqItem.request = current.request.sys_id;

reqItem.cat_item = '80df599bdba3320007a2fe1ebf9619ff';   //Sys_id of Training Catalog Item

reqItem.short_description = "Training Tracking for New provider";

reqItem.stage = "request_approved";

reqItem.approval = "requested";

reqItem.insert();

I added the same script to Run Script activity in the New Provider workflow.   A second RITM was created under the same REQ...BUT (and it's a big one) the Training Workflow was not run or tied to the new REQ.   I did search online and couple of posts directed me here, but that is what I tried first.

Any advice on what I am missing?

1 ACCEPTED SOLUTION

randrews
Tera Guru

this is a script i use to create a number of new req items inside an existing request.. it is wrapped in a for loop since it is going to crerate multiple items.. just eliminate that loop... bottom line is FIRST you create the item... and associate to the current request.. THEN you go through and set all variables that you need.. so where i am setting the variables.. take mine out put in yours and add any lines needed to get em all..



my apologies to whoever i stole this code/idea from!   this runs in a script box inside of your workflow.. obviously replace the sys_id i have in my code with your own<the sys id for the maintain item you are creating an item for>







list = current.variables.v_xxxx_additional_secured_area_acc.toString();


var list_split = list.split(',');


var secure_area = 'e891c69d13a1fe008e9c7e276144b03c'; //sid for the wecure item access




for(var counter = 0 ; counter< list_split.length; counter++){


//create a new item in the request


var reqHelper = new GlideappCalculationHelper();


                reqHelper.addItemToExistingRequest(current.request, secure_area, 1); // 1 is the qty


                reqHelper.rebalanceRequest(current.request);



//find the item and update itsvariables


var grReqItem = new GlideRecord('sc_req_item');


                grReqItem.addQuery('request', current.request);  


                grReqItem.addQuery('cat_item',secure_area);  


                grReqItem.addQuery('parent','');


                grReqItem.query();  


if(grReqItem.next()) {


//gs.addInfoMessage('Found item ' + grReqItem.number);


                                grReqItem.variables.requested_for = current.variables.requested_for;


                                  grReqItem.variables.v_area = list_split[counter];


                                    grReqItem.parent = current.sys_id;


                                    grReqItem.update();


}


}


View solution in original post

13 REPLIES 13

the for loop is controlled by this variable...

list = current.variables.v_xxxx_additional_secured_area_acc.toString();

what this is doing is getting the list collector that stores the number of arreas that need access and storing as a string..

this line var list_split = list.split(',');

then converts that to an array... without knowing how you are trying to set the loop.. do you always want two is it variable from a list collector or how... we can't help you.

 

Hi randrews,

 

Even I have the list collector variable in my form.

 

When I am selecting the number of values in the list collector (say more than 2), it is always creating 2 RITMs only.

 

Below is my code in the "Run Script" Activity in the Workflow:

 

var soft =current.variable_pool.software_search_sa2.getDisplayValue();
var s=soft.split(",");
var secure_area = '40960a9213170600ff267d322244b0d1'; //sys id of the Multiple Software Request Catalog Item

for(var counter = 1 ; counter< s.length; counter++){


//create a new item in the request

var reqHelper = new GlideappCalculationHelper();


reqHelper.addItemToExistingRequest(current.request, "40960a9213170600ff267d322244b0d1", 1); // 1 is the qty


reqHelper.rebalanceRequest(current.request);



//find the item and update its variables


var grReqItem = new GlideRecord('sc_req_item');


grReqItem.addQuery('request', current.request);


grReqItem.addQuery('cat_item',"40960a9213170600ff267d322244b0d1");

grReqItem.orderByDesc('sys_created_on');


grReqItem.query();


if(grReqItem.next()) {



grReqItem.variables.requested_for = current.variables.requested_for;


grReqItem.variables.software_search_sa = s[counter];

grReqItem.variables.software_search_sa2 = s[counter];


grReqItem.parent = current.sys_id;


grReqItem.update();


}


}

 

But it is failing 😞

Thanks & Regards,

Ram Prakash

This solution is almost working perfectly for me.   Have you had any issues when writing the value of a variable that was included as activity results for a switch statement. 

With the solution provided my workflow constantly hangs at the switch.   

 

My activity results are expecting 'new_device' and this is the value that i'm passing.   

Wow, after 5years this was still Super helpful, thank you!