- 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-04-2023 08:45 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 10:29 AM
Hi @pkman ,
To verify the correctness of your script, consider adding debug statements that display info messages for all variables, including the data you are retrieving. This approach will help you identify and potentially reproduce the issue more effectively
Thanks,
Anand