- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2015 04:01 PM
I need to add an item to an existing request.
The workflows require that certain variables exist and I'll need them to be visible in later tasks.
Some time ago (Calgary) I attempted to create them manually. However, this caused a problem in that, while I could access the variables, I could not display them in tasks.
The only solution that was proposed was creating a request item by using the Cart API to create a new cart and request.
The Cart API doesn't appear to have any options for adding to an existing request, and the only "solution" I've found in the community, is to create the Request item in this way, then delete the request.
Obviously this is a really ugly solution, especially since it kicks off tasks and workflows before I have a chance to delete it.
Is there a better solution that I'm just not finding?
Thanks,
-Stephen
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2015 08:54 AM
Hi Stephen,
Have you tried to create a new RITM within the same REQ using GlideappCalculationHelper? I found it awhile back, either here on the Community or some other site, but it's helped us to create an item in the same REQ. Unfortunately, I can't remember where I found it so I couldn't really explain how it works. It's not pretty, but at least you don't have to delete a REQ.
function addItem() {
// add item to current request
var reqHelper = new GlideappCalculationHelper();
reqHelper.addItemToExistingRequest(current.request, 'sys_id of item', 1); // 1 is the qty
reqHelper.rebalanceRequest(current.request);
// update/add values to variables on item
var grReqItem = new GlideRecord('sc_req_item');
grReqItem.addQuery('request', current.request);
grReqItem.addQuery('cat_item','sys_id of item');
grReqItem.query();
if(grReqItem.next()) {
grReqItem.variables.some_true_false_var = true;
grReqItem.variables.some_other_var = 'Yes';
grReqItem.parent = current.sys_id;
grReqItem.variables.comments = "Add any comments here.";
grReqItem.update();
}
}
Also, have you tried adding the variables needed to both the current item and the item being added? If you have the workflow from Item A create Item B, making sure you set the "parent" of Item B as the sys_id of Item A, you could have Item B refer back to Item A by using the "parent" field and updating the variables that way (query for Item A using "parent" and then set the variables).
We do something like this in some other workflow, but this might be more complicated than necessary.
Anyway, hope some of this helps!
Barb
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2017 08:36 AM
Hi Nestor,
If you still having an issue with this, post the exact code you are using up here so people can take a look at what may be happening.
Without seeing your code, one thought on what may be happening. Are you manually submitting a request for the request that you are creating via the script? Not sure if that makes sense, but it sounds like you could be ordering the item containing the script to order the item again, so it would just go off reordering itself in a loop.
Tommy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2017 07:49 AM
Thanks Barb... this was a HUGE help...
I had an item where I needed to enable people to request access to multiple areas for their badge.. each area has different approvers...
by wrapping this script in a for loop.. .and modifying the item query to look for an empty parent i was able to build a loop that basically allows a dynamic number of approvers... 😎 < I create one item for each area with a requested for and the area.. that items workflow looks up the approver and gets the approvals>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2017 04:54 AM
Hi Raymond,
I had an item where I need to create multiple request items based on list collector values and each value will have it's own set of approver's..... I am able to create multiple request items under the same request with out any issues using the script provided above. But, I am having issue's when I am trying to read variables in a workflow for the newly created request items. These variables are showing up fine in the UI when I am clicking on the request item, but somehow I am not able to read them in the workflow using the script. Following is script I am to using log all the variables information in a request item. Other than the parent request item, all child request items are not logging any variable information. Any support on this would be greatly appreciated, Thank you!
var sys_id = current.sys_id;
var reqItem = new GlideRecord('sc_req_item');
reqItem.get(sys_id);
workflow.info('Logging request item number {0}', current.number);
workflow.info('Logging Comments {0}', reqItem.variables.u_additional_comments);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2017 06:59 AM
If you are doing the above in a workflow, you should be able to do a run script and just gs.log(current.variableName) for each variable in each of the child workflows. Have you tried logging that way and did it work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2017 07:29 AM
Hi Thomas, I just tried your suggestion by using the current variable in the workflow. But still, the log is showing an empty value for all the child request items. I have also copied the screen shots of workflow activity for the both parent and child request items to give you a better idea.
workflow.info('Logging Comments using current {0}', current.variables.u_additional_comments);
Screen shot of workflow activity for parent request item. You can see it logged 'dfdd' as comments.
Screen shot of workflow activity for child request item. You can see it didn't logged any comments even after using the 'current' variable
THANKS!