- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2024 05:50 AM
Hey everyone,
I created a scheduled job to run once a week to create a catalog item automatically for weekly task. I am able to get the script to populate the variables, but I also have a MRVS in the catalog item I would like to populate. Below is my script and attached a picture of the MRVS details. Can anyone help with what I need to add for the MRVS to populate those fields? Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2024 07:19 PM
Hi @jonsr20,
No worries, it looks like you can't set an MRVS via Cart API.
You can update the MRVS after creating the request - https://www.servicenow.com/community/now-platform-forum/set-multi-row-variable-set-using-cart-api/m-...
But there is another workaround using CartJS API which did its job- https://www.servicenow.com/community/now-platform-articles/cartjs-how-to-populate-a-mrvs-multi-row-v...
So, for your example, it will be something like:
var mrvsObj = [{
"details": "Test 123",
"audit_stockroom": "102eb8c4c300f1103e0637af05013104",
"completion_date": "2024-05-30 11:11:46 PM"
},
{
"details": "Test 123456",
"audit_stockroom": "d82eb8c4c300f1103e0637af05013103",
"completion_date": "2024-05-30 11:31:46 PM"
}
];
var cart = new sn_sc.CartJS();
var item = {
'sysparm_id': 'a74ee200c32682903e0637af0501312f',
'sysparm_quantity': '1',
'variables': {
'requested_for' : '1c0c47ef971b85108d663fe3f153afc7', //add the remaining variables here
'stockroom_audit': JSON.stringify(mrvsObj)
}
};
var cartDetails = cart.addToCart(item);
var checkoutInfo = cart.checkoutCart();
Make sure you double check the date/time format as it may needs some adjustment
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2024 07:19 PM
Hi @jonsr20,
No worries, it looks like you can't set an MRVS via Cart API.
You can update the MRVS after creating the request - https://www.servicenow.com/community/now-platform-forum/set-multi-row-variable-set-using-cart-api/m-...
But there is another workaround using CartJS API which did its job- https://www.servicenow.com/community/now-platform-articles/cartjs-how-to-populate-a-mrvs-multi-row-v...
So, for your example, it will be something like:
var mrvsObj = [{
"details": "Test 123",
"audit_stockroom": "102eb8c4c300f1103e0637af05013104",
"completion_date": "2024-05-30 11:11:46 PM"
},
{
"details": "Test 123456",
"audit_stockroom": "d82eb8c4c300f1103e0637af05013103",
"completion_date": "2024-05-30 11:31:46 PM"
}
];
var cart = new sn_sc.CartJS();
var item = {
'sysparm_id': 'a74ee200c32682903e0637af0501312f',
'sysparm_quantity': '1',
'variables': {
'requested_for' : '1c0c47ef971b85108d663fe3f153afc7', //add the remaining variables here
'stockroom_audit': JSON.stringify(mrvsObj)
}
};
var cartDetails = cart.addToCart(item);
var checkoutInfo = cart.checkoutCart();
Make sure you double check the date/time format as it may needs some adjustment
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 04:54 AM
That worked, thanks James you are awesome!
Jonathan