
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-11-2021 02:50 AM
Hi Everyone,
I'm using the cart API as follows to create some orders automatically (inside some scripted REST API)
var cartId = GlideGuid.generate(null); |
However it's not working, the order is created with an empty multi row variable set, trying to supply a stringified JSON is not working, how can I proceed?
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-11-2021 03:08 AM
you cannot set MRVS using Cart API.
You can update the variable post RITM creation
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('someCatalogItemId');
//fill in the variables on the request item form
cart.setVariable(item, "asset", "00a96c0d3790200044e0bfc8bcbe5dc3");
cart.setVariable(item, "multiple_choice", "Phoenix");
var rc = cart.placeOrder();
// query RITM and update that
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', rc.sys_id);
ritm.query();
if(ritm.next()){
ritm.variables.someMultiRowVariableSetName = "[{\"plugin_name\":\"plugin 1\"},{\"plugin_name\":\"plugin 2\"}]";
ritm.setWorkflow(false);
ritm.update();
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2022 07:35 PM
Thank you for sharing.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-11-2024 04:42 AM
Hi Ankur,
I have tried the above one, when try to hard code the values to Multi row variable set it is working, but when i try to fetch the value from the request body it is not working, Below is the script i have written and calling rest api.
var request_body = request.body.nextEntry();
Please find the screenshot for request body. Could you please help me how to do this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2022 08:14 PM
In the Rhome version, I was able to get this to work.
- Create a JSON object
- Stringify the JSON object
- Put square brackets at the start [ and ] end of the JSON string.
Pasted below is an example of the string being hard coded into the item variable.
var cart = new sn_sc.CartJS();
var item = {
'sysparm_id': 'a9cad13a2f110110c9ebdcb6f699b6fa',
'sysparm_quantity': '1',
'variables': {
'string_on_base_vars': 'Sample String Value',
'mrvs_demo': '[{"mrvs_date_var":"2022-02-04","mrvs_checkbox_var":"true"}]'
}
};
var cartDetails = cart.addToCart(item);
var checkoutInfo = cart.checkoutCart();
gs.info(checkoutInfo);
Detailed article on MRVS/CartJS: CartJS: How to populate a MRVS (Multi Row Variable Set)
CartJS API: https://developer.servicenow.com/dev.do#!/reference/api/sandiego/server/sn_sc-namespace/c_CartJSScop...