Adding sum of integer fields to another field on a form (Client Side)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2019 02:42 PM
I'm trying to sum multiple integer fields into one on a form. I would like this to be done before the form is saved or submitted AND I need this calculation to trigger based on multiple fields.
I have about 9 fields that if either one is NOT NULL then I want the calculation to run and populate the sum into a total field. Due to these conditions I'm trying to accomplish this in an UI policy rather than a client script.
My current code is the following. I've tried using parseInt and adding '+' in front of the integer field. With the code below the field being populate with the total is stating NaN.
function onCondition() {
var appDev = g_form.getValue('u_app_dev_eta_of_hours');
var applServ = g_form.getValue('u_appl_services_emr');
var sumHours = parseInt(appDev) + parseInt(applServ);
g_form.setValue('u_total_hrs_for_prj_rsrc_work',sumHours);
//g_form.setDisplay('u_total_hrs_for_prj_rsrc_work', +u_app_dev_eta_of_hours + 'u_appl_services_emr');
}
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2019 03:16 PM
What is the type of u_total_hrs_for_prj_rsrc_work? It should be integer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2019 03:19 PM
try this
function onCondition() {
var appDev = g_form.getValue('u_app_dev_eta_of_hours');
var applServ = g_form.getValue('u_appl_services_emr');
var sumHours = parseInt(appDev,10) + parseInt(applServ,10);
g_form.setValue('u_total_hrs_for_prj_rsrc_work',sumHours);
//g_form.setDisplay('u_total_hrs_for_prj_rsrc_work', +u_app_dev_eta_of_hours + 'u_appl_services_emr');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2019 10:53 AM
I also tried adding ,10 as you stated, but when I enter numbers into the fields, the Total Hours field populates with NaN.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2019 11:40 AM
Can you please send the screen shot of UI Policy? Also, check if variable names are correct.