Joget DX 8 Stable Released
The stable release for Joget DX 8 is now available, with a focus on UX and Governance.
...
Code Block | ||
---|---|---|
| ||
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); |
Anchor | ||||
---|---|---|---|---|
|
...
Code Block |
---|
import java.util.Map; import org.joget.directory.model.User; public boolean isAuthorized(User user, Map params) { //using hash variable to get "creator" field value and escapes it with java syntax, then compare with current username return "#form.crm_account.creator?java#".equals(user.getUsername()); } //call isAuthorized method with injected variable return isAuthorized(user, requestParams); |
Anchor | ||||
---|---|---|---|---|
|
...
If your script need to reuse for multiple times in an app or can be used by others app in future development, please consider to make your Bean Shell script as a plugin instead of copy and paste it multiple times across your app. Bean Shell script is harder to maintain in this case. Imagine that you want to make a change, you will have to update all the places that are using the same script as well. Beside that, a normal plugin implementation will have better performance than a script running by a Bean Shell interpreter.
If partial of your script can be done by existing plugins in Joget Workflow, you can reuse the plugin in stead of writting it again.
To reuse a plugin, you can retrieve the plugin using PluginManager, then set it properties and execute it.
Example:
Children Display |
---|