1
0
-1

Hi Folks ¡  i need validate that a calculation field  be greater than 1 (one), someone  have an example to do it with bean shell?

thanks

 

  1. Fabian Barrera

    Specifically, i´m using this code as reference but need an example that work with numbers import java.util.Arrays; import org.joget.apps.app.service.AppUtil; import org.joget.apps.form.model.Element; import org.joget.apps.form.model.Form; import org.joget.apps.form.model.FormData; import org.joget.apps.form.service.FormUtil; public boolean validate(Element element, FormData formData, String[] values) { boolean result = true; //get field 1 value from form data object String field1Id = "field1"; Form form = FormUtil.findRootForm(element); Element field1 = FormUtil.findElement(field1Id, form, formData); if (field1 != null) { //get value of field 1 String[] compareValues = FormUtil.getElementPropertyValues(field1, formData); //compare the value of field 2 and field 1 are equals if (!Arrays.equals(values, compareValues)) { String id = FormUtil.getElementParameterName(element); formData.addFormError(id, "Value not equal!!!!"); result = false; } } else { //ignore if the field 1 not exist } return result; } //call validate method with injected variable return validate(element, formData, values);

CommentAdd your comment...

1 answer

  1.  
    2
    1
    0

    Try this. You need to code in java.

    if(Integer.parseInt(values[0]) < 1){
        formData.addFormError("calculatonFieldID", "Must be more than 1."); //change field id to your calculation field
    	return false;
    }else{
    	return true;
    }
      CommentAdd your comment...