Multirow variable set data missing when submitted through Service Portal

johnsonjohn
Tera Contributor

Hello - we are using a multirow variable set in one of our catalog items (contains 6 variables).  When the catalog item is submitted through the Service Portal, a lot of the data that was entered in the MRVS is missing when viewed in the platform.  When the same catalog item is submitted through the platform with the same data in the MRVS, all data is retained.

I haven't seen anything in the community describing this issue, and the closest thing I found in HI is not exactly the same (https://hi.service-now.com/kb_view.do?sysparm_article=KB0713584).  This seems to be a Service Portal issue.  Has anyone experienced this or able to provide some insight?  Thanks in advance!

1 ACCEPTED SOLUTION

After you posted the code of OnChange script I could reproduce the problem and I can suggest a workaround.

The main problem in your code exist in the line

g_form.setValue('u_ukbilling_total_inc_vat', total, total);

where total variable is a Number. As the result the value of multirow variable set uk_billing_invoice_details_new will be JSON string like

[{
	"uk_billing_total_inc_tax": 1,
	"uk_billing_sales_order_number": "b",
	"uk_billing_net_amount": "1",
	"uk_billing_invoice_number": "a",
	"uk_billing_tax_rate": "3"
}]

where the value of u_ukbilling_total_inc_vat variable is a number instead of a string. It's unclear why exactly, but it produce some problem in later processing of the data.

To fix the problem you can use for example the following code

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}

	//Type appropriate comment here, and begin script below
	var netamount = g_form.getValue('net_amount');
	var vatrate = g_form.getValue('tax_rate');
	var vattotal = parseInt((vatrate/100) * netamount, 10);
	var total = parseInt(netamount, 10) + parseInt(vattotal, 10);

	g_form.setValue('total_inc_tax', String(total));
}

where one sets string value. After the changes the problem was fixed in my test environment.

View solution in original post

12 REPLIES 12

johnsonjohn
Tera Contributor

Hi Olegki, thanks for taking the time to test.  To answer your questions, I am using the Madrid version and the widget is out of box, original.

After reading about your test, I tried some more things and I think I have figured out what is causing the problem, but I'm not sure why it's doing that.  In my MRVS variable set (Invoice Details), I have an onchange client script to perform a calculation.  There are 3 fields: Net Amount, Tax Rate and Total Inc Tax.  The calculation is Total Inc Tax = Net Amount + (Net Amount * Tax Rate).  The script is this:

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

//Type appropriate comment here, and begin script below

var netamount = g_form.getValue('u_ukbilling_net_amount');
var vatrate = g_form.getValue('u_ukbilling_vat_rate');
var vattotal = parseInt(((vatrate/100) * netamount));
var total = parseInt(netamount) + parseInt(vattotal);

g_form.setValue('u_ukbilling_total_inc_vat', total, total);
}

When I disable this script, everything is working fine -- all values are captured correctly when entered through SP.  When this script is active, data is missing.  So evidently something is not behaving correctly in this script when executed through SP.  Unfortunately, my scripting skills are very limited so I'm not sure what the problem is (the script works fine through the UI).  Do you have any idea what might be wrong?  Or is there another way I can do the calculation without using this script?

Thank you again for your help.

After you posted the code of OnChange script I could reproduce the problem and I can suggest a workaround.

The main problem in your code exist in the line

g_form.setValue('u_ukbilling_total_inc_vat', total, total);

where total variable is a Number. As the result the value of multirow variable set uk_billing_invoice_details_new will be JSON string like

[{
	"uk_billing_total_inc_tax": 1,
	"uk_billing_sales_order_number": "b",
	"uk_billing_net_amount": "1",
	"uk_billing_invoice_number": "a",
	"uk_billing_tax_rate": "3"
}]

where the value of u_ukbilling_total_inc_vat variable is a number instead of a string. It's unclear why exactly, but it produce some problem in later processing of the data.

To fix the problem you can use for example the following code

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}

	//Type appropriate comment here, and begin script below
	var netamount = g_form.getValue('net_amount');
	var vatrate = g_form.getValue('tax_rate');
	var vattotal = parseInt((vatrate/100) * netamount, 10);
	var total = parseInt(netamount, 10) + parseInt(vattotal, 10);

	g_form.setValue('total_inc_tax', String(total));
}

where one sets string value. After the changes the problem was fixed in my test environment.

johnsonjohn
Tera Contributor

Hi Olegki, that solved the problem.  I updated the script per your suggestion, and it is now working as expected.  Thank you so much!