Bean Shell Validator not working

Confluence User - 03 Oct, 2017
i tried to use the script provide by joget but nothing is working. Please at least provide us some working example app for this bean shell validator.
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);
forms

1


04 Oct, 2017
confluenceUser
confluenceUser

Hi, I tried the example provided in Bean Shell Programming Guide#UseasFormValidator and it works fine. What is the error that you are getting?

RELATED QUESTIONS

Your answer


To answer a question you'll need an account.

Print