How to access MRVS variables inside MRVS Client Script Multirow Variable Set
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2023 06:29 AM
I am able to access MRVS variables outside MRVS Variable set. But how to access variables inside multi row variable set for client script. TIA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2023 06:49 AM
Thank You
I have use case where I need to total all the values in the Multi Row Variable set, when Add button clicked it should show total amount of all the rows that has been entered until now. Screenshot below for your reference. If I click on Add here, it should give me total of all the rows added in the MRVS for a particular field
This should show an alert total score until now is 290. How is this possible.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2023 06:55 AM
check this link on how to detect the add/remove button and based on that show the alert
MRVS detect when a row is removed or deleted
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2023 07:37 AM
Thank You
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2023 07:20 PM
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2023 08:15 AM
An onLoad catalog client script is needed in the MRVS. In that client script use the g_service_catalog.parent.getValue('name_of_mrvs_here') to gather all the rows of the MRVS.
Reference docs: https://docs.servicenow.com/bundle/utah-api-reference/page/app-store/dev_portal/API_reference/g_serv...
An example:
function onLoad() {
//get the MRVS value (all rows)
var mrvs = g_service_catalog.parent.getValue('camping_items);
if(mrvs){
//mrvs comes in as a stringified JSON object. Parse encode it to use it as a normal array of objects. Each object is a row
var mrvsJSON = JSON.parse(mrvs);
//use logic to get to the needed count. I used the .reduce array method
var counts = mrvsJSON.reduce(function(acc, curr){
acc += parseInt(curr.item_count);
return acc;
},0)
g_form.showFieldMsg('item_count', "Max quantity is 20. You are currently at " + counts)
}
}
Rendered example: