1 Reply Latest reply on Nov 4, 2014 7:00 AM by try67

    Validate Two Calculated Field Values Match

    KDRamsey

      How would you do the custom validation scripts when two fields being compared are calculated? Example: field1 is the product of three entries and field2 is the sum of 15 entries. The results of the two calculated fields should be compared, and an alert displayed if they do not match.

       

      I believe the document level script I found below on related discussion Re: Field Validation will work to compare the values and run only when the values are null, but I'm not sure how to construct the custom validation scripts for the calculated fields.

       

      // document level script for comparison of 2 fields
      function FieldsEqual(cFieldName1, cFieldName2) {
      var bValidation = true;
      if(event.target.name == cFieldName1){
      cField1 = event.value;
      cField2 = this.getField(cFieldName2).value;
      }

      if(event.target.name == cFieldName2){
      cField1 = event.value;
      cField2 = this.getField(cFieldName2).value;
      }

      if(cField1 != "" && cField2 != ""){
      // fields are not empty;
      if (cField1 != cField2) {
      // fields are not equal
      app.alert("Fields are not the same", 1, 0); // alert
      bValidation = false; // set event.rc for failed validation;
      } // end fields not equal
      } // end fields not null
      return bValidation; // return status of comparison;
      } // end 2FieldsEqual function;
      // end of doucment level function comparing 2 fields

       

      I am new to javascript, so any assistance is much appreciated.

       

      Thank you.