Storing Grid Data in Multiple Tables
Confluence User - 02 Dec, 2018
I want to store a grid data in multiple tables: in the parent table as serialized JSON, and in a separate table utilizing multi-row form binder.
Here's my current Implementation utilizing BeanShell Store Binder.
The MultirowFormBinder is working perfectly. However, the DefaultFormBinder, which I suppose it will store the grid in the parent form table as serialized JSON, is actually storing the grid rows as separate rows in the parent table.
I want to store it as a serialized JSON in a single column. What am I missing here?
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.joget.apps.app.service.AppUtil;
import org.joget.apps.form.model.Element;
import org.joget.apps.form.model.FormData;
import org.joget.apps.form.model.FormRowSet;
import org.joget.apps.form.model.FormStoreBinder;
import org.joget.commons.util.LogUtil;
import org.joget.plugin.base.Plugin;
import org.joget.plugin.base.PluginManager;
import org.joget.plugin.enterprise.MultirowFormBinder;
public class MultirowStoreScript {
private static void log(String message) {
LogUtil.info(MultirowLoadScript.class.getName(), message);
}
private static Plugin getPluginByName(String pluginName) {
PluginManager pluginManager = (PluginManager) AppUtil.getApplicationContext().getBean("pluginManager");
return pluginManager.getPlugin(pluginName);
}
private static void storeInDifferentTable(Element element, FormRowSet rows, FormData formData) {
MultirowFormBinder formBinder = (MultirowFormBinder) getPluginByName("org.joget.plugin.enterprise.MultirowFormBinder");
formBinder.setProperty("formDefId", "item");
formBinder.setProperty("foreignKey", "parent_id");
formBinder.store(element, rows, formData);
}
private static void storeInParentTableAsSerializedJson(Element element, FormRowSet rows, FormData formData) {
FormStoreBinder storeBinder = (FormStoreBinder) getPluginByName("org.joget.apps.form.lib.DefaultFormBinder");
storeBinder.store(element, rows, formData);
}
public static void execute(Element element, FormRowSet rows, FormData formData) {
storeInParentTableAsSerializedJson(element, rows, formData);
storeInDifferentTable(element, rows, formData);
}
}
MultirowStoreScript.execute(element, rows, formData);
storebinder