The CreatorCon Call for Content is officially open! Get started here.

Client Script to add variables

pkman
Tera Contributor

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);
   
}

 

 

1 ACCEPTED SOLUTION

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);
   
}

 

AnandKumarP_2-1696442128696.png

 

 

AnandKumarP_1-1696441955969.png

Please mark it as helpful and solution proposed if it helps.

Thanks,

Anand

 

View solution in original post

6 REPLIES 6

Screen Shot 2023-10-04 at 11.42.03 AM.png

Anand Kumar P
Giga Patron

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