Troubleshooting an issue with a MRVS in a catalog Item

Chris33
Tera Contributor

I am trying to troubleshoot an issue with a MRVS in a catalog Item.  The MRVS contains purchase items ...

 

Name   Type   Question  Order

mrvs_cost_center Reference Cost Center 100

account_number Reference Account Number 110

quantity Single Line Text Quantity 120

unit_price Single Line Text Unit Price 130

vendor Reference Supplier/Vendor 140

description Multi Line Text Description 150

total Single Line Text Total 160

 

When a new row is added i need to do a calculation of unit_price * quantity and then store that value in the total variable of the MRVS row.  It should be pretty straightforward but I can't update the total value shown on the row.  my onChange script works when I change the quantity but I need it work when i add the row, and trying to duplicate the code in an onload script didn't work for me. 

 

 

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}
	var formatter = new Intl.NumberFormat('en-US', {style: 'currency', currency: 'USD', });
	
	if (isNaN(parseInt(newValue))) {
		g_form.setValue("quantity", "");
		g_form.addErrorMessage("Please provide an integer value for Quantity.");
	} else {
		g_form.setValue("quantity", parseInt(newValue));
		if (g_form.getValue("unit_price") != "") {
			var mrvs_total = parseInt(g_form.getValue("quantity")) * parseFloat(g_form.getValue("unit_price"));
			g_form.setValue("total", formatter.format(mrvs_total));
		}
	}
}

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Chris33 

so basically you want to observe if new row is added or removed.

If yes then check these links which have the solution for it, enhance as per your requirement

MRVS detect when a row is removed or deleted 

Widget that reacts to onChange event of Variable 

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

View solution in original post

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@Chris33 

so basically you want to observe if new row is added or removed.

If yes then check these links which have the solution for it, enhance as per your requirement

MRVS detect when a row is removed or deleted 

Widget that reacts to onChange event of Variable 

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