...
- Same org.joget.apps.form.model.FormRowSet object which stored.
Samples:
Use as Form Validator
Injected Variables:
...
- A boolean value to indicate the validation pass or fail.
Samples:
Use as Form Multi Row Load Binder
Injected Variables:
...
Compare the submitted value with the value of another field.
Code Block |
---|
|
import java.util.Arrays;
import org.joget.apps. |
...
...
service.AppUtil;
import org.joget.apps.form.model.Element;
import org.joget.apps.form.model. |
...
Expected Return Object:
...
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); |
Use as Form Multi Row Load Binder
Injected Variables:
- element - Element that this binder is tie to. (org.joget.apps.form.model.Element)
- primaryKey - The primary key provided by the element to load data. (java.lang.String)
- formData - The data holder of the whole form. (org.joget.apps.form.model.FormData)
Expected Return Object:
- An org.joget.apps.form.model.FormRowSet object which contains one or more org.joget.apps.form.model.FormRow object.
Samples:
Use as Form Multi Row Store Binder
Injected Variables:
- element - Element that this binder is tie to. (org.joget.apps.form.model.Element)
- rows - Data to be store. Contains one or more org.joget.apps.form.model.FormRow object. (org.joget.apps.form.model.FormRowSet)
- formData - The data holder of the whole form. (org.joget.apps.form.model.FormData)
Expected Return Object:
- Same org.joget.apps.form.model.FormRowSet object which stored.
Samples:
Use as Form Multi Row Validator
Injected Variables:
- element - Element that this validator is tie to. (org.joget.apps.form.model.Element)
- rows - Submitted data. Contains one or more org.joget.apps.form.model.FormRow object. (org.joget.apps.form.model.FormRowSet)
- formData - The data holder of the whole form. (org.joget.apps.form.model.FormData)
Expected Return Object:
- A boolean value to indicate the validation pass or fail.
Samples:
Use as Form Permission
Injected Variables:
- user - User object of current logged in user (org.joget.directory.model.User)
- requestParams - Request parameters map of current HTTP Request (java.util.Map)
Expected Return Object:
- A boolean value to indicate the user is authorized.
Samples:
Check the current user's username are same with the form field "creator" value. The following sample using Form Hash Variable to retrieve form field value.
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); |
Use as Form Post Submission Processing Tool
Injected Variables:
- workflowAssignment - The workflow activity assignment object of the saving form. Null when the form is not an assignment form. (org.joget.workflow.model.WorkflowAssignment)
- pluginManager - Plugin Manager service bean for convenient usage. (org.joget.plugin.base.PluginManager)
- appDef - App definition of the process. (org.joget.apps.app.model.AppDefinition)
- request - Http Request object of current Http Request. (javax.servlet.http.HttpServletRequest)
Expected Return Object:
Samples:
Use as Process Participant
Injected Variables:
- pluginManager - Plugin Manager service bean for convenient usage. (org.joget.plugin.base.PluginManager)
- workflowActivity - Workflow Activity that trying to retrieves assignee. (org.joget.workflow.model.WorkflowActivity)
Expected Return Object:
- A java.util.Collection of username in java.lang.String to be assign to the Workflow Activity.
Samples:
Randomly assign an user in a department to a workflow activity
Code Block |
---|
|
import java.util.ArrayList;
import java.util.Collection;
import org.joget.apps.app.service.AppUtil;
import org.joget.directory.model.User;
import org.joget.directory.model.service.ExtDirectoryManager;
import org.joget.workflow.model.WorkflowActivity;
public Collection getAssignees(WorkflowActivity activity) {
Collection assignees = new ArrayList();
ExtDirectoryManager directoryManager = (ExtDirectoryManager) pluginManager.getBean("directoryManager");
String deptId = "D-005";
//Get total user in department
Long total = directoryManager.getTotalUsers(null, null, deptId, null, null, null, null);
//Get random number from 0 to the total number of users in department
int random = (int) (Math.random() * total);
//Get users using directory manager
Collection userList = directoryManager.getUsers(null, null, deptId, null, null, null, null, "firstName", false, random, 1);
for(Object u : userList){
User user = (User) u;
assignees.add(user.getUsername());
}
return assignees;
}
//call getAssignees method with injected variable
return getAssignees(workflowActivity); |
Samples:
Use as Form Multi Row Store Binder
Injected Variables:
- element - Element that this binder is tie to. (org.joget.apps.form.model.Element)
- rows - Data to be store. Contains one or more org.joget.apps.form.model.FormRow object. (org.joget.apps.form.model.FormRowSet)
- formData - The data holder of the whole form. (org.joget.apps.form.model.FormData)
Expected Return Object:
- Same org.joget.apps.form.model.FormRowSet object which stored.
Samples:
Use as Form Multi Row Validator
Injected Variables:
- element - Element that this validator is tie to. (org.joget.apps.form.model.Element)
- rows - Submitted data. Contains one or more org.joget.apps.form.model.FormRow object. (org.joget.apps.form.model.FormRowSet)
- formData - The data holder of the whole form. (org.joget.apps.form.model.FormData)
Expected Return Object:
- A boolean value to indicate the validation pass or fail.
Samples:
Use as Form Permission
Injected Variables:
- user - User object of current logged in user (org.joget.directory.model.User)
- requestParams - Request parameters map of current HTTP Request (java.util.Map)
Expected Return Object:
- A boolean value to indicate the user is authorized.
Samples:
Use as Form Post Submission Processing Tool
Injected Variables:
- workflowAssignment - The workflow activity assignment object of the saving form. Null when the form is not an assignment form. (org.joget.workflow.model.WorkflowAssignment)
- pluginManager - Plugin Manager service bean for convenient usage. (org.joget.plugin.base.PluginManager)
- appDef - App definition of the process. (org.joget.apps.app.model.AppDefinition)
- request - Http Request object of current Http Request. (javax.servlet.http.HttpServletRequest)
Expected Return Object:
Samples:
Use as Process Participant
Injected Variables:
- pluginManager - Plugin Manager service bean for convenient usage. (org.joget.plugin.base.PluginManager)
- workflowActivity - Workflow Activity that trying to retrieves assignee. (org.joget.workflow.model.WorkflowActivity)
Expected Return Object:
- A java.util.Collection of username in java.lang.String to be assign to the Workflow Activity.
Samples:
Use as Process Tool
Injected Variables:
...
Expected Return Object:
Samples:
Use as Userview Permission
...
- A boolean value to indicate the user is authorized.
Samples:
Best Practices
...
1. Only import classes that are needed
...
3. Indents your script nicely and follows the Java Code Conventions
...
It will make yours and others life easier to maintain and review the script whenever necessary as Joget Workflow provided flexibility to adapt change quickly.
...