Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
import org.joget.apps.form.model.Element;
import org.joget.apps.form.model.FormData;
import org.joget.apps.form.model.FormRow;
import org.joget.apps.form.model.FormRowSet;
import org.joget.apps.form.service.FormUtil;
import org.joget.plugin.base.PluginManager;
import org.joget.apps.form.model.FormLoadBinder;

public FormRowSet load(Element element, String primaryKey, FormData formData) {
    String defaultFormDefId = "default_grid_entry"; //change this to the form id used to store default grid data
    String formDefId = "grid_entry";  //change this to the form id used to store grid data
    String foreignKey = "fk"; //change this to the foreign key 
    
    FormRowSet f = new FormRowSet();
    f.setMultiRow(true);

    // Reuse Multi Row Binder to load data
    PluginManager pluginManager = (PluginManager) FormUtil.getApplicationContext().getBean("pluginManager");
    FormLoadBinder binder = (FormLoadBinder) pluginManager.getPlugin("org.joget.plugin.enterprise.MultirowFormBinder");
    
    //Load from the grid table
    binder.setProperty("formDefId", formDefId);
    binder.setProperty("foreignKey", foreignKey);
    f = binder.load(element, primaryKey, formData);
    
    //if no grid data is retrieved, get from default table
    if (f == null || f.isEmpty()) {
        binder.setProperty("formDefId", defaultFormDefId);
        
        //set the foreign key value to empty
        f = binder.load(element, "", formData);
    }
    return f;
}

//call load method with injected variable
return load(element, primaryKey, formData);

...

  1. Reuse Multi Row Binder plugin to load data
  2. Reuse Email Tool to send email

9. How to use 3rd party libraries in Bean Shell

In your webserver, you can add the jar file to your WEB-INF/lib folder and restart the server. Then, you should be able to "import" and use them in your bean shell java code. 

More samples

Children Display