This post explains how you can retrieve data from another form grid and make a comparison with it. The code below is used in multirow bean shell validator in a second form grid (ID: "formgrid2") in the same form.

import java.util.Arrays;
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;
import org.joget.apps.form.dao.FormDataDao;
import org.joget.apps.form.model.FormRow;
import org.joget.apps.form.model.FormRowSet;
import org.joget.plugin.base.PluginManager;
import org.joget.apps.form.model.FormLoadBinder;
import org.joget.commons.util.LogUtil;
import java.util.Collection;
import java.util.Map;
import java.util.List;

public boolean validate(Element element, FormData formData, FormRowSet fg2Rows) {
    boolean result = false;

    //get form grid 1 value from form data object
    String fg1Id = "formgrid1"; //insert form grid field id here
    Form form = FormUtil.findRootForm(element);
    Element fg1 = FormUtil.findElement(fg1Id, form, formData);

        FormRowSet fg1Rows = fg1.formatData(formData); //we can iterate through each row of the "formgrid1" grid in FormRowSet
		fg1RowCount = fg1Rows.size();
		fg2RowCount = fg2Rows.size();

        //insert logic here. Below is a sample validation to make sure that fg1 row count needs to be same or more than fg2 row count
		if(fg1RowCount >= fg2RowCount ){
        	result = true;

    return result;

//call validate method with injected variable
return validate(element, formData, rows);
  • No labels