How to access MRVS variables inside MRVS Client Script Multirow Variable Set

Raviteja K
Tera Expert

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

9 REPLIES 9

Hi @Ankur Bawiskar 

 

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

 

Raviteja12_0-1699282027230.png

 

Raviteja12_1-1699282112281.png

This should show an alert total score until now is 290. How is this possible.

 

@Raviteja K 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Thank You

@Raviteja K 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

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:

mrvs_value_sum.gif