
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2017 06:35 PM
Hi guys,
I have been trying to modify a script i originally used to calculate a division of 3 fields i have created.
since then the business owner has changed their mind and want to remove the calculation of 1 of those fields.
this is the script i am currently using:
function onChange(control, oldValue, newValue, isLoading) {
var distanceHomeToWork = Number(g_form.getValue("u_distance_home_to_work"));
var totalDistanceTravelled = Number(g_form.getValue("u_total_distance_travelled"));
var distanceToReimburse = Number(totalDistanceTravelled - distanceHomeToWork);
if (distanceToReimburse != "NaN" && distanceToReimburse > 0) {
var reimbursementAmount = distanceToReimburse * .66;
//g_form.setValue("u_total_claimable", reimbursementAmount); - keep this line commented out.
var x = reimbursementAmount;
g_form.setValue("u_total_claimable", x.toFixed(2));
}
}
The screenshot below shows what i now need to calculate:
Sorry, this is probably super simple but i am just not seeing it.
I tried:
function onChange(control, oldValue, newValue, isLoading) {
//do nothing, just loading the function below
}
function divide_a_by_b() {
var a = parseInt(g_form.getValue('u_total_distance_travelled'),10);
var b = parseInt(g_form.getValue('u_amount'),10);
var result = 0; // force to zero if infinite
if (b != 0) {
var result = (a/b).toFixed(2);
}
g_form.setValue('u_total_claimable',result);
}
and:
function onChange(control, oldValue, newValue, isLoading) {
//do nothing, just loading the function below
}
function divideBy(){
var totaldist = Number(g_form.getValue('u_total_distance_travelled')).value;
var amount = Number(g_form.getValue('u_amount'))* .66;
g_form.setValue('u_total_claimable') = totaldist / amount;
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2017 08:47 PM
Hi Philip,
Hope this works:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var result = 0; // force to zero if infinite
var a = g_form.getValue('u_total_distance_travelled');
var b = g_form.getValue('u_amount');
if (b != 0) {
var numobj = parseInt(a) / parseFloat(b);
result = numobj.toFixed(2);
}
g_form.setValue('u_total_claimable',result);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2017 07:21 PM
Hi Philip,
Can you please try with below code.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var result = 0; // force to zero if infinite
var a = g_form.getValue('u_total_distance_travelled');
var b = g_form.getValue('u_amount');
if (parseInt(b) != 0) {
var numobj = parseInt(a) / parseInt(b);
result = numobj.toFixed(2);
}
g_form.setValue('u_total_claimable',result);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2017 08:17 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2017 08:47 PM
Hi Philip,
Hope this works:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var result = 0; // force to zero if infinite
var a = g_form.getValue('u_total_distance_travelled');
var b = g_form.getValue('u_amount');
if (b != 0) {
var numobj = parseInt(a) / parseFloat(b);
result = numobj.toFixed(2);
}
g_form.setValue('u_total_claimable',result);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2017 09:23 PM
Worked a treat!!!! Thank you.