- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2019 07:08 AM
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2019 07:34 AM
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();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2019 07:34 AM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2019 07:58 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2019 06:30 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2019 03:52 AM
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 😞