Usages
This page focuses on practical applications of Bean Shell scripting in Joget. It provides specific examples and scenarios for using scripts to manipulate data, automate workflows, and extend functionality within your Joget apps.
Use as Form 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 that contains oneorg.joget.apps.form.model.FormRow
object.
- An
- Samples:
- Load user data using JDBC.
Use as Form Options Binder
- Injected Variables:
element
- Element that this binder is tied 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 that contains one or moreorg.joget.apps.form.model.FormRow
object. AllFormRow
objects are expected to have "value" and "label" properties.
- An
- Samples:
- Load time zone as the select box options.
Use as Form Ajax Options Binder
- Injected Variables:
values
- Dependency values of the controlling field (java.lang.String[]
).
- Expected Return Object:
- An
org.joget.apps.form.model.FormRowSet
object that contains one or moreorg.joget.apps.form.model.FormRow
object. AllFormRow
objects are expected to have "value" and "label" properties.
- An
- Samples:
- Load user as options based on the group id passed by the controlling field.
Use as Form Store Binder
- Injected Variables:
element
- Element that this binder is tied to (org.joget.apps.form.model.Element
).rows
- Data to be stored. Contains only oneorg.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 is stored.
- Same
- Samples:
- Calculate the data before storing it using the Workflow Form Binder.
Use as Form Validator
- Injected Variables:
element
- Element that this validator is tied to (org.joget.apps.form.model.Element
).values
- The submitted values of the element (java.lang.String[]
).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
orfail
.
- A boolean value to indicate the validation
- Samples:
- Compare the submitted value with the value of another field.
-
- Textfield / Textarea length not exceeding 500 characters:
-
- Field value does not exceed 500 in numerical value:
Use as Form Multi Row Load Binder
- Injected Variables:
element
- Element that this binder is tied 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 that contains one or moreorg.joget.apps.form.model.FormRow
object.
- An
- Samples:
- Load default grid data from another table if current record does not have any grid data.
Use as Form Multi Row Store Binder
- Injected Variables:
element
- Element that this binder is tied to (org.joget.apps.form.model.Element
).rows
- Data to be store. Contains one or moreorg.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
org.joget.apps.form.model.FormRowSet
object.
- A
- Samples:
- Bulk create users based on the grid data.
Use as Form Multi Row Validator
- Injected Variables:
element
- Element that this validator is tied to (org.joget.apps.form.model.Element
).rows
- Submitted data. Contains one or moreorg.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
orfail
.
- A boolean value to indicate the validation
- Samples:
- Validate that the sum of column values is less than 1000.
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 is used to indicate that the user is authorized.
- Samples:
- Check that the current user's username is the same as the form field "creator" value. The following sample uses the Form Hash Variable to retrieve the form field value.
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:
- None
- Samples:
- Reuse the Email tool to send separate emails to each user. The following script is for a form not mapped to workflow assignment; therefore,
workflowAssignment
is not available.
- Reuse the Email tool to send separate emails to each user. The following script is for a form not mapped to workflow assignment; therefore,
Use as Datalist Action
- Injected Variables:
httpRequest
- HTTP Request object of current HTTP Request (javax.servlet.http.HttpServletRequest
).datalist
- Datalist object of the current datalist (org.joget.apps.datalist.model.Datalist
).rowKeys
- A String array of record ID(s) for datalist row(s) that is selected for this action.
- Expected Return Object:
- None
- Samples:
Use as Datalist Formatter
- Note:
- The entire script is defaulted to be applied to every row in the specified column, hence it is not needed to perform looping to manually apply formatting to every row.
- It is also possible to use a hash variable in the returned value.
- Injected Variables:
datalist
- Datalist object of the current datalist (org.joget.apps.datalist.model.Datalist
).column
- The current datalist column object (org.joget.apps.datalist.model.DataListColumn
).row
- row Object of current record row in the datalist.
To retrieve the property value from the Object row, use this service method:-
DataListService.evaluateColumnValueFromRow
(Object row, StringpropertyName
).
-
value
- the value of the current row as String.
- Expected Return Object:
- A String value to replace the original row value.
- Samples:
- 1) Example code using DataListService service method to evaluate column value "
Name
" from row object.
- 1) Example code using DataListService service method to evaluate column value "
-
- 2) Format the row value by appending hash variable.
Use as Process Participant
- Injected Variables:
pluginManager
- Plugin Manager service bean for convenient usage (org.joget.plugin.base.PluginManager
).workflowActivity
- Workflow Activity that tries to retrieve assignee (org.joget.workflow.model.WorkflowActivity
).
- Expected Return Object:
- A
java.util.Collection
of username injava.lang.String
to be assigned to the Workflow Activity.
- A
- Samples:
- Randomly assign a user in a department to a workflow activity.
Use as Process Tool
- Injected Variables:
workflowAssignment
- The workflow tool activity assignment object (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. Not available if the tool is triggered by Deadline (javax.servlet.http.HttpServletRequest
).
- Expected Return Object:
- None
- Samples:
- Start a new process in the same app with the current record id.
-
- Update Form Field Value:
-
- Start a new process instance for each row of data loaded using foreign key and value:
Use as Process Route Decision
- Note:
- By using a decision plugin, the specified route transition rules configured explicitly in the process design will be ignored.
- Injected Variables:
appDef
- App definition of the process (org.joget.apps.app.model.AppDefinition
).pluginManager
- Plugin Manager service bean for convenient usage (org.joget.plugin.base.PluginManager
).processDefId
- The process definition ID of the current process instance.processId
- The process instance ID of the current process instance.routeId
- The ID of the route node currently configured on.
- Expected Return Object:
- A
org.joget.workflow.model.DecisionResult
object.
- A
- Samples:
- Decide to approve or reject a request based on the value of the workflow variable "status".
Use as Userview 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 is used to indicate that the user is authorized.
- Samples:
- Check the user is in a group and is an admin user.