- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 08:57 AM
I need to add 6 values together and provide a total. I would like this to display in the catalog item. I have used input from the community, and for some strange reason still cannot get the field to calculate. Below is my script. I tried the same using several methods on the calculation (number, parseInt, etc). The "total" field is unaffected.
function onChange(control, oldValue, newValue ) {
if (newValue == '') {
return;
}
var air = g_form.getValue('air');
var hotels = g_form.getValue('hotels');
var meals = g_form.getValue('meals');
var transportation = g_form.getValue('transportation');
var fuel = g_form.getValue('fuel');
var misc = g_form.getValue('misc');
var total = parseFloat(air) + parseFloat(hotels) + parseFloat(meals) + parseFloat(transportation) + parseFloat(fuel) + parseFloat(misc);
g_form.setValue('total',total);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 10:54 AM - edited 10-04-2023 10:55 AM
Hi @pkman ,
I have tried in my PDI its working you can user below script
function onChange(control, oldValue, newValue, isLoading) {
if (newValue === '' || isNaN(newValue)) {
g_form.setValue('total', '');
return;
}
var air = parseFloat(g_form.getValue('air')) || 0;
var gas = parseFloat(g_form.getValue('gas')) || 0;
var water = parseFloat(g_form.getValue('water')) || 0;
var total = air + gas + water;
g_form.setValue('total', total);
}
Please mark it as helpful and solution proposed if it helps.
Thanks,
Anand

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 10:08 AM
@pkman I tested with the following script and it runs fine for me.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var fuel=g_form.getValue('fuel');
var hotel=g_form.getValue('hotel');
var total = parseFloat(fuel)+parseFloat(hotel);
g_form.setValue('total',total);
}
Could you please share the snapshot of your Client script form here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 08:44 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 10:42 AM - edited 10-04-2023 10:46 AM
@pkman Where are you testing this feature on Service Portal or backend? If you are testing on the Service Portal then play change the UI Type to All and the script will start working on portal too.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 10:54 AM - edited 10-04-2023 10:55 AM
Hi @pkman ,
I have tried in my PDI its working you can user below script
function onChange(control, oldValue, newValue, isLoading) {
if (newValue === '' || isNaN(newValue)) {
g_form.setValue('total', '');
return;
}
var air = parseFloat(g_form.getValue('air')) || 0;
var gas = parseFloat(g_form.getValue('gas')) || 0;
var water = parseFloat(g_form.getValue('water')) || 0;
var total = air + gas + water;
g_form.setValue('total', total);
}
Please mark it as helpful and solution proposed if it helps.
Thanks,
Anand