Expand my Community achievements bar.

Need to blank calculated field depending in calculation

Avatar

Former Community Member
I am having a simple form derived from the examples, which shows numSum = numQty*numCost.

This works fine and numSum is blank until both operands are entered.

But if add other fields for numDiscount and finalSum with the caluculation



finalSum = numQty*numCost - (numQty*numCost /100 * numDiscount)



then finalSum always displays 0.00 regardless whether the previous fields have been filled or not.



How can this be avoided?



regards, Dieter
1 Reply

Avatar

Level 1

//------------------------------------------------------------------------------------

// 1st parameter array with names of fields for check

// 2nd parameter is string "All" or "One" ...determine all or one must be not null ...

//------------------------------------------------------------------------------------

function MyCheckValueToNull(aFieldsNames,OneOrAll)

{

   var All_IsNotNull = 1;

   var One_IsNotNull = 0;

   for (i = 0; i < aFieldsNames.length; i++) {

       if(getField(aFieldsNames[i]).value === ""){

          All_IsNotNull = 0;

       }else{

          One_IsNotNull = 1;

       }

   }

   if(OneOrAll == "One"){

      return One_IsNotNull;

   }else if(OneOrAll == "All"){

      return All_IsNotNull;

   }else{

      return null;

   }

}

//----------------------------

//--- sample how to use ------

      var aFieldsNames = [

          "numQty",

          "numCost",

          "numDiscount"

      ];

      var lCheck = MyCheckValueToNull(aFieldsNames,"All");

      if(lCheck == 1){

         event.value = getField(aFieldsNames[0]).value*getField(aFieldsNames[1]).value - (getField(aFieldsNames[0]).value*getField(aFieldsNames[1]).value /100 * getField(aFieldsNames[2]).value);

      }else{

         event.value = "";

      }