- 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 06:50 AM
Hi Ozawa -san
Thanks for comment.
I can show you the situation. Actually I have 7 fields for input and 1 field for showing the result.
1st field is the calculate result field(Total)
2nd field ~ 8th field you can input any number.
For example, When I input 1+2+3+4+5+6+70 , the client script worked as expected and the result was correct, it shows 91.
But after I saved the form, you can see the total changed to 21, the value in 8th field was not calculated.
I tried to deleted the client script for 8th field and create a same client script for it. It looks ok in the first time, but after that same issue happened on another field ( 2nd field or 4th field).
I have no idea what is the root cause for this one.
Thanks,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2022 10:53 PM
Hi,
So the situation is as below.
- there is a custom table with fields 1 to 8 of type decimal
- there is a client script on field 8 that would sum fields 2 to 8 and set the total in field 1.
- When the values are entered in the form, field 1 contains the correct sum of fields 2 to 8
- Form is "Saved" and is selected from the list view. Value of field 1 is changed to a different value
Is the above situation true?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2022 11:51 PM
1. I've created a table with fields1 to 8 that have type Decimal.
2. Create onChange client script on variable Field8
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var fieldNames = ['u_field2', 'u_field3', 'u_field4', 'u_field5', 'u_field6', 'u_field7'];
var sum = 0;
for (var i = 0; i < fieldNames.length; i++) {
sum += Number(g_form.getValue(fieldNames[i]));
}
sum += Number(newValue);
g_form.setValue('u_field1', sum.toFixed(2));
}
3. Open a form and enter values in fields 2 through 8.
4. Click on "Submit" button to save fields. Fields and values are shown on the list and are correct.
5. Click on created record to re-open the record. The values are correct.
- 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';
}