To trigger multiple request items on a single request based on the list collector variable value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2024 09:58 AM
Hi All,
Requirement : To trigger multiple request items on a single request based on the list collector variable value.
for ex. After form is submitted. Under one Request multiple RITM will be created and Each RITM have their own separate task. I am using flow designer to create catalog task but do not how create multiple ritm through it
Thanks in Advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2024 10:31 AM
Have you looked into ordering guides?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2024 10:43 AM - edited 04-06-2024 10:48 AM
Hey @Aman Trivedi1 ,
We did the same thing for one of the client.
- Create a Record Producer & Catalog item with same variables & same variable backend name.
- Do not display the catalog item on portal (by not giving catalog & category, but keep it active)
- Record Producer should create a record in Custom Table with all the variables.
- BR should trigger in from Insert of record in that custom table
- BR script will use Cart API & create the no of RITMs in FOR loop for the created request
Sample Script for CART API
As an example, I’ll present a script that would hypothetically be used to order a laptop using the cart API. This could exist in a business rule or workflow or any other context where it would be useful.
var id = GlideGuid.generate(null); // Generate a new GUID
var cart = new Cart(id); // Instantiate a fresh cart
var RITM = cart.addItem('060f3afa3731300054b6a3549dbe5d3e'); // The value used here is the sys_id of our laptop catalog item
cart.setVariable(RITM,'ram','16'); /**/
cart.setVariable(RITM,'os','win10'); /* Catalog item variables can be populated */
cart.setVariable(RITM,'storage','1tb'); /**/
var request = cart.placeOrder(); // The placeOrder() function returns a GlideRecord for the sc_request record it generates
Additionally, another API available within SN may be needed for interacting with the cart. Specifically, within a scoped context, you’ll want to make use of the CartJS API. Below is an example of how to use this API to complete the same objective as the script above.
var cart = new sn_sc.CartJS();
var item = { // Note that values using CartJS are instantiated via a JSON object
'sysparm_id': '060f3afa3731300054b6a3549dbe5d3e',
'sysparm_quantity': '1',
'variables': {
'ram': '16',
'os': 'win10',
'storage': '1tb'
}
};
var cartVals = cart.addToCart(item); // The addToCart function returns a JSON object reflecting the status of the cart
var checkoutVals = cart.checkoutCart(); // The checkoutCart function returns a JSON object with info about the submitted cart, contents varying if two-step checkout is active
Another Sample
(function executeRule(current, previous /*null when async*/ ) {
gs.include('Cart');
var access = current.u_variable_1_value.toString().split(',');
var cartId = GlideGuid.generate(null); //unique ID for cart
var cart = new Cart(cartId);
gs.addInfoMessage("executed");
for (var i = 0; i < access.length; i++) {
var item = cart.addItem(current.u_catalog_sys_id);
cart.setVariable(item, 'requested_for', current.u_requested_for);
cart.setVariable(item, 'please_select_non_human_id', access[i]);
cart.setVariable(item, 'requesting_for', access[i]);
cart.setVariable(item, 'u_requester', current.u_requested_for);
cart.setVariable(item, current.u_variable_2_name, current.u_variable_2_value);
cart.setVariable(item, current.u_variable_3_name, current.u_variable_3_value);
cart.setVariable(item, current.u_variable_4_name, current.u_variable_4_value);
cart.setVariable(item, current.u_variable_6_name, current.u_variable_6_value);
cart.setVariable(item, current.u_variable_7_name, current.u_variable_7_value);
}
var rc = cart.placeOrder();
rc.requested_for = current.u_requested_for;
rc.short_description = "ABC ";
current.u_record_created = rc.getDisplayValue();
current.u_request_sys_id = rc.sys_id;
// current.update();
rc.update();
})(current, previous);
🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2024 10:56 AM
Hi @DanielCordick
Requirement is to stick with a Service catalog.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2024 10:57 AM
By using an order guide you are still using the service catalog