- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2022 11:33 PM
Hi,
I have some client script to calculate value.
The script was run correctly but when I save the form, the total number was not correct.
The value in one filed was not saved.
I tried to recreated the client script, some time it fixed, but another script changed to failed again.
Any I deal to fix this issue???
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
newValue ='0,0';
}
var h1 = g_form.getDecimalValue('u_value1');
if (h1 === '') {
return;
}
var h2 = g_form.getDecimalValue('u_value2');
if (h2 === '') {
return;
}
var newValue2 = newValue.replace(/,/g,'');
var total = parseFloat(newValue2) + parseFloat(h2);
var totalhour = total.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
g_form.setValue('u_hours_total', totalhour + '');
//Type appropriate comment here, and begin script below
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2022 06:30 PM
Hi found the issue of my code.
When the record is saved and the form is reloaded, the onChange client scripts should not be running, but they are running to set the newValue to 0 and then calculate the total.
Here is the root cause:
if (isLoading || newValue === '') {
newValue ='0,0';
}
Solution: Change the code as below
if (isLoading) {
return;
}
if (newValue === '') {
newValue = '0,0';
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2022 03:02 AM
Hello.
Could you please check if another client script or UI policy working on same field.
Regards,
Akshay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2022 06:51 AM
I have checked I don not have another UI policy / client script on the same filed.
Client script run as well but after I save the form, the data was not correct.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2022 03:26 AM
Hi,
Would appreciate some more information. What is the script suppose to do? Which variable is onChange set to?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2022 03:38 AM
Hi again,
Looking at the script, it seems to be adding values of u_value1 and u_value2 fields and setting u_hours_total field. The onChange script seems to be set of variable u_value1. Is there a similar script on u_value2 field?
>The value in one filed was not saved.
Exactly, which field? u_value1, u_value2, u_hours_total?
Does this mean the value does not appear in Requested Item when the form is submitted?
I've tested the script and it is saving the values as variables in requested item.
>I tried to recreated the client script, some time it fixed, but another script changed to failed again.
So, there is another script? It's failing in another script? Please paste the another script that is failing.