Set value outside Multi Row Variable Set (MRVS) on the service portal

J_r_my1
Kilo Guru

Hello,

I have created a record producer with two variable set, one of it is multi-row variable set. I wanted to update a variable outside my multi row variable set, I am not able to do it on the service portal, but it's working on the backend.

I have tried to used 

// This is working on backend but not on service portal
var total = parseFloat(newValue);
parent.g_form.setValue('montant',total);


//with this code I am able to get value outside of the multi row variable set
var spThis = this;
var catItem = spThis.angular.element(spThis.$('#sc_cat_item').find('sp-variable-layout')[0]).scope();
var parent_g_form = catItem.getGlideForm();

//this is working
alert(parent_g_form.getValue('caller'));

//this isn't working
parent_g_form.g_form.setValue('calculate',total);

 

So if anyone has been able to do it or have come across the same issue

 

1 ACCEPTED SOLUTION

Hi,

refer this link for workaround

MRVS detect when a row is removed or deleted

Regards
Ankur

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

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can form array of json object and set the mrvs variable value

Regards
Ankur

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

Hi sorry, I might no formulate it correctly.

I am trying to calculate the total price of several item pick up in multi row variable set so I have created this script

 var multiRowVariableSet = JSON.parse(g_form.getValue('commande'));
	//alert(gr.length);
	//var myString = JSON.stringify(gr);
	var total = 0;	
	
	
	
	for (var i = 0; i < multiRowVariableSet.length; i++) {

           total = parseFloat(multiRowVariableSet[i].total_price) + parseFloat(total);
        
    }

g_form.setValue('montant',total);

So this working, but I need something to trigger my script when someone add or remove an item in multi row variable set

Hi,

refer this link for workaround

MRVS detect when a row is removed or deleted

Regards
Ankur

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

I have been able to do it.

Thanks for your help

I have use the following script in my widget : 

function($scope) {

 $scope.$watch(function() {
	 
    return $scope.page.g_form.getValue('commande');
    }, function(value) {
	 //alert(value);
	var test = $scope.page.g_form.getValue('commande');
	 //alert(test);
       $scope.page.g_form.setValue('calulate',test);
});
 
}