Based On value changes Grand total has to change
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2025 05:57 AM
Hi All,
I have created a custom form where the grand total should be calculated based on the values entered in the fields. I have implemented a Business Rule that updates the grand total after saving the form, and it is working fine. However, the issue is that if the user changes the value of any field (e.g., Freight), the grand total should update immediately before saving the form.
How can I achieve this?
business rule script :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2025 06:33 AM
you will require 5 onChange 1 each on these fields and set the total. But better to use 1 before update business rule
u_freight_cap, u_installation_startup_cap, contingency_cap, u_sub_cap, u_tax_total_cap
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2025 06:35 AM
something like this on 1 field and then you will have to repeat for other 4 field
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
// Retrieve the values from the form fields
var capFreight = parseFloat(g_form.getValue('u_freight_cap')) || 0;
var capStartup = parseFloat(g_form.getValue('u_installation_startup_cap')) || 0;
var capContingency = parseFloat(g_form.getValue('contingency_cap')) || 0;
var capSubTotal = parseFloat(g_form.getValue('u_sub_cap')) || 0;
var capTaxTotal = parseFloat(g_form.getValue('u_tax_total_cap')) || 0;
// Perform the calculation
var totalAll = capSubTotal + capTaxTotal + capFreight + capStartup;
var contingencyAmount = (totalAll * capContingency) / 100;
var grandTotal = totalAll + contingencyAmount;
// Update the form fields with the calculated values
g_form.setValue('u_gtotal_cap', grandTotal);
g_form.setValue('u_capital', grandTotal);
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2025 07:06 AM
Hi Ankur,
I have tired this script but its not working
Thanks,
Suresh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2025 08:05 PM
what debugging did you perform?
those fields are on form or not?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader