RITM should start only after another RITM is closed complete

RudhraKAM
Tera Guru

I have a order guide in which when a request is raised it will create 2 RITMs ( 2 different catalog items ) my requirement is 

test A catalog item  ritm should be finish until then test 2 catalog item RITM should be on pause , the one way i am thinking of doing it is to put a wait condition on test 2 workflow and check if the request have test 1 catalog item then wait until its finish , and the code follows as below , there is some issue with code can some one help me with this code 

var gr = new GlideRecord('sc_req_item');
gr.addQuery('request', current.request);
gr.addQuery('cat_item', "99fb579bdbbb73401e49f9051d96191f");
gr.addQuery('state',"3");
gr.query();
gs.log(" For RITM " +current.number +" the ROW Count is " +gr.getRowCount() );
if(gr.getRowCount() == '1'){
	answer = true;
}

 

and also please suggest me if you have any other scalable solution 

1 ACCEPTED SOLUTION
8 REPLIES 8

Hello David 

I just added this run script code in the Test 1 catitem ( last activity before end but still not working 

 

setting the state to work in progress

var gr = new GlideRecord('sc_req_item');
gr.addQuery('request', current.request);
gr.addQuery('cat_item', "784c5f57dbbb73401e49f9051d961962");
gr.query();
gs.log(" For RITM " +current.number +" the ROW Count is " +gr.getRowCount() );
//if(gr.getRowCount() == '0'){
if(gr.next())
	{
state = 2;
}

I see you found a useful article to make the order guide a viable option. If, down the road, you find you do actually need to create ritm's from the master request wf the code you'll need in your run script is like below:

var ritmID = '<sys_id>'; //sid for the catalog item access

//create a new item in the request

var reqHelper = new GlideappCalculationHelper();
reqHelper.addItemToExistingRequest(current.getUniqueValue(), ritmID, "1"); // 1 is the qty
reqHelper.rebalanceRequest(current.getUniqueValue());

//find the item and update itsvariables
var grReqItem = new GlideRecord('sc_req_item');
grReqItem.addQuery('request', current.getUniqueValue());
grReqItem.addQuery('cat_item', ritmID);
grReqItem.query();
if(grReqItem.next()) {
	
	grReqItem.short_description = 'add a short description here';
	grReqItem.variables.variable_name1 = value1;
	grReqItem.variables.variable_name2 = value2;
        grReqItem.variables.variable_name3 = value3;
        grReqItem.variables.variable_name4 = value4;
	
	grReqItem.update();
	
}

benn23
ServiceNow Employee
ServiceNow Employee

You need to 'nudge' the 2nd Item to get its workflow to re-evaluate the 'wait for' conditions.

In your 'update worknotes' 'run script' activity, add something like this:

var itmId = 'sys_id_of_catalog_item_that_is_waiting';

var secondItm = new GlideRecord('sc_req_item');
secondItm.addEncodedQuery('request=' + current.request + '^cat_item=' + itmId);
secondItm.query();
if(secondItm.next()){
new Workflow().broadcastEventToCurrentsContexts(secondItm, 'update', null);
}