Create multiple RITMs when a request is submitted for a catalog item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2017 06:32 AM
Hi All,
I am trying to create multiple RITM's under the same request, when a user submits a request for an item. The user will have the option to select No. of users in a variable and submit the request. Based on the user count, those many RITM's should be created for the same request. I already have a workflow attached to that catalog item and i need to make the changes in that workflow, so that when the request is submitted, based on the user count multiple RITM's should be generated under that request.
I have already tried the 'GlideappCalculationHelper' API, but it gets into infinte loop by generating multiple RITM's. Please let me know, if there are any other options to accomplish this task.
Thanks in Advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2017 06:42 AM
It looks like this is your answer:
How to add a new item to an existing request with catalog variables
if you are having issues with your script can you please post it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2017 07:16 AM
Hi Nathan,
Thanks for your response. I have gone through the thread which you have mentioned, but still the issue persists. I am posting the complete script for your perusal. This script will be attached in the Run Script activity of the workflow. In the item, user can select upto 10 users while submitting the request. Based on the number of users, those many RITM's should be generated. I will be passing the value of the respective user stored in a hidden variable to its respective RITM. I am yet to add that condition the script. I had added a flag 'created_by_user' which will not allow the RITM's generated through this script to generate even more RITM's.
var users = current.variables.no_of_users;
if(current.variables.created_by_user == 'Yes' && current.variables.created_by_user != ''){
for(i=0; i<=users-1; i++)
{
var reqHelper = new GlideappCalculationHelper();
reqHelper.addItemToExistingRequest(current.request, current.cat_item, current.quantity);
reqHelper.rebalanceRequest(current.request);
var grReqItem = new GlideRecord('sc_req_item');
grReqItem.addQuery('request', current.request);
grReqItem.orderByDesc('sys_created_on');
grReqItem.query();
if(grReqItem.next()) {
grReqItem.variables.user_1 = '4740021837275240fd26b05943990eae';
grReqItem.variables.created_by_user = 'No';
grReqItem.parent = current.sys_id;
grReqItem.update();
}
}
}
Could you please let me know, where is the issue.
Thanks in Advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2017 07:33 AM
var users = current.variables.no_of_users;
if(current.variables.created_by_user == 'Yes' && current.variables.created_by_user != ''){
for(i=0; i<=users-1; i++) {
var reqHelper = new GlideappCalculationHelper();
reqHelper.addItemToExistingRequest(current.request, current.cat_item, current.quantity);
reqHelper.rebalanceRequest(current.request);
var grReqItem = new GlideRecord('sc_req_item');
grReqItem.addQuery('request', current.request);
grReqItem.orderByDesc('sys_created_on');
grReqItem.query();
if(grReqItem.next()) {
grReqItem.variables.user_1 = '4740021837275240fd26b05943990eae';
grReqItem.variables.created_by_user = 'No';
grReqItem.parent = current.sys_id;
grReqItem.update();
}
}
}
Please find the code in a neater format.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-03-2018 01:22 PM
Did you ever get this resolved. I am running into same issue