- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2025 02:38 PM
Our team created a form that has 5 integer columns that are supposed to add up to 100 and display in another integer column that displays that total.
Each of the 5 individual integer columns have the following onChange client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) { // || newValue === ''
return;
}
//Type appropriate comment here, and begin script below
var minValue = 25; //g_form.getValue('critical_element_1_min_weight');
//alert(minValue)
var m1, m2, m3, m4, m5;
if (newValue) {
m1 = parseInt(newValue);
} else {
m1 = 0;
}
if (g_form.getValue('critical_element_2_weight')) {
m2 = parseInt(g_form.getValue('critical_element_2_weight'));
}else {
m2 = 0;
}
if (g_form.getValue('critical_element_3_weight')) {
m3 = parseInt(g_form.getValue('critical_element_3_weight'));
}else {
m3 = 0;
}
if (g_form.getValue('critical_element_4_weight')) {
m4 = parseInt(g_form.getValue('critical_element_4_weight'));
}else {
m4 = 0;
}
if (g_form.getValue('critical_element_5_weight')) {
m5 = parseInt(g_form.getValue('critical_element_5_weight'));
}else {
m5 = 0;
}
if (oldValue != newValue) {
if (parseInt(newValue) < minValue) {
g_form.clearValue('critical_element_1_weight');
g_form.showFieldMsg('critical_element_1_weight', 'Please input a value greater than or equal to the minimum value of ' + minValue, 'error');
}
}
g_form.setValue('critical_element_total_weight', m1 + m2 + m3 + m4 + m5);
}
The total integer column has the following onSubmit client script:
function onSubmit() {
// initialize vars to capture weights
var weight1 = parseInt(g_form.getValue('critical_element_1_weight'));
var weight2 = parseInt(g_form.getValue('critical_element_2_weight'));
var weight3 = parseInt(g_form.getValue('critical_element_3_weight'));
var weight4 = parseInt(g_form.getValue('critical_element_4_weight'));
var weight5 = parseInt(g_form.getValue('critical_element_5_weight'));
var sumOfWeights = weight1 + weight2 + weight3 + weight4 + weight5;
if (sumOfWeights !== 100) {
alert('Total assigned weights for critical elements must equal 100.');
return false;
}
alert(g_form.getValue('critical_element_total_weight'))
}
When the total equals 100 and we press submit, the alert pops up showing 100 and the column has the value of 100:
However, once we clear the alert, we get the "Record Updated" info message, and the column value disappears. It also does not get saved in the back-end table. We've checked to see if there are any other scripts interfering with this and there aren't any. Any ideas why this is happening?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2025 09:29 AM
Hi All, thanks for the help! Turns out the onSubmit client script wasn't saving the value. I ended up creating a script include that updates the value onSubmit. It is working now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2025 07:07 AM
Since you mentioned that it is working well at the native view and the issue is on the portal?
Can you please hide Save (Ctrl + S) UI action and expose the "Save" UI action?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2025 09:29 AM
Hi All, thanks for the help! Turns out the onSubmit client script wasn't saving the value. I ended up creating a script include that updates the value onSubmit. It is working now.