How to add a request item to a request in a workflow

Dubz
Mega Sage

Hi All,

I have a workflow that triggers when a type of request is created, as part of this workflow i need to add additional request items depending on various inputs.

I've tried using the create task activity to create a request item but it doesn't seem possible to set variables, i tried task.variables.<variableName> = <variableValue> to no avail. I've also tried a run script activity after my create task where i glide into the new RITM record and add variable values there, still no joy.

Does anyone know the best way to do this? I could completely script it but i was hoping to avoid a workflow just filled with run scripts.

Cheers

Dave

 

1 ACCEPTED SOLUTION

Michael Fry1
Kilo Patron

You can use a run script to generate extra RITMs and populate the variables. The script looks like this where variables.x - x is the name of the variable to populate:

var access = '8ac559c8db0722004d12f33eae9619a6'; //sid for the catalog item access

//create a new item in the request

var reqHelper = new GlideappCalculationHelper();
reqHelper.addItemToExistingRequest(current.request, access, "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',access);
grReqItem.addNullQuery('configuration_item');
grReqItem.query();
if(grReqItem.next()) {
	
	//gs.addInfoMessage('Found item ' + grReqItem.number);
	grReqItem.variables.requested_for = current.variables.requested_for;
	//Dover Food Retail
	grReqItem.variables.type = current.variables.type;
	grReqItem.variables.access_level = current.variables.access_level;
	grReqItem.contact_type = current.request.contact_type;
	grReqItem.request.special_instructions = "Access request auto-generated by System";
	
	grReqItem.update();
	
}


View solution in original post

4 REPLIES 4

Michael Fry1
Kilo Patron

You can use a run script to generate extra RITMs and populate the variables. The script looks like this where variables.x - x is the name of the variable to populate:

var access = '8ac559c8db0722004d12f33eae9619a6'; //sid for the catalog item access

//create a new item in the request

var reqHelper = new GlideappCalculationHelper();
reqHelper.addItemToExistingRequest(current.request, access, "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',access);
grReqItem.addNullQuery('configuration_item');
grReqItem.query();
if(grReqItem.next()) {
	
	//gs.addInfoMessage('Found item ' + grReqItem.number);
	grReqItem.variables.requested_for = current.variables.requested_for;
	//Dover Food Retail
	grReqItem.variables.type = current.variables.type;
	grReqItem.variables.access_level = current.variables.access_level;
	grReqItem.contact_type = current.request.contact_type;
	grReqItem.request.special_instructions = "Access request auto-generated by System";
	
	grReqItem.update();
	
}


Thanks Michael, i'd found that script on another article on here but i was wondering if there was a way to do it with the create task activity. It just seems odd that you can't use that to populate variables on request items. 

Andrew_TND
Mega Sage
Mega Sage

Hiya,

If I can avoid using scripts I will do. 🙂

Have you tried messing around with the workflow step as per below? You could could throw an 'If' step in there as well which would differentiate it between the two. 

find_real_file.png

Yeah i've tried using the create task activity but you can't add variables to request items there. The trouble is that variables are set on the sc_item_option and associated with the request item via a relationship on the sc_item_option_mtom table so you can't dot-walk through to them from the request item. 

Looks like the only way is by run script is Michael has suggested. Bit annoying, have to pair them up with 'wait for condition' activities and then arrange triggers on the request to satisfy the condition, rather than just ticking the 'wait for completion' box 😞