Joget Workflow v6 Beta 3 Released

Check out the latest Joget Workflow v6 Beta for many new features and improvements in user experience (UX), app maintainability and performance.

Skip to end of metadata
Go to start of metadata

What is it for?

  • Joget Workflow provided Bean Shell implementation as several Plugin Types. Please refer to usages section.
  • BeanShell is a small, embeddable Java source interpreter with object scripting language features written in Java.
  • BeanShell dynamically executes standard Java syntax in runtime.
  • By using BeanShell Plugin, you can type in valid Java codes in plugin configuration and the statements will be executed when the plugin is triggered.
  • No compilation cycle is needed.

What is the code syntax?

Usages

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 which contains one org.joget.apps.form.model.FormRow object. 

Samples:

Load user data using jdbc.

Use as Form Options 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. All FormRow objects are expected to have "value" and "label" property.

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 which contains one or more org.joget.apps.form.model.FormRow object. All FormRow objects are expected to have "value" and "label" property.

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 tie to. (org.joget.apps.form.model.Element)
    • rows - Data to be store. Contains only one 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:

Do some calculation before storing the data using Workflow Form Binder.

Use as Form Validator

Injected Variables:

    • element - Element that this validator is tie 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 or fail.

Samples:

Compare the submitted value with the value of another field.

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:

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 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:

Bulk create users based on the grid data.

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:

Validate the sum of a column values are 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 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.

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 Email tool to send separate email to each users. The following script is for a form not mapped to workflow assignment, therefore workflowAssignment is not available.

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.

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 trigger by Deadline. (javax.servlet.http.HttpServletRequest)

Expected Return Object:

    • None

Samples:

Start a new process in the same app with current record id.

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 to indicate the user is authorized.

Samples:

Check the user is in a group and is an admin user.

Best Practices

1. Only import classes that are needed

Do not use wildcard in import statement. It giving a very bad performance in Bean Shell interpreter to search the whole package and loads it in memory.

Don't:

Do:

2. Do not need to mention the type of element of a collections

Bean Shell interpreter cannot recognise the element type syntax of collections class like Collection, Map, List, Set and etc.

Don't:

Do:

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.

4. Write your script in functions

If your script is pretty long and some parts of the script are reusable, please make use of function to write your script. It provided better reading and performance.

5. Remember to write some comments 

It will helps you and others to understand what is the purpose for the script quickly. 

6. Catch the exceptions and give a meaningful message in log.

If you are using a lot of Bean Shell Scripting in your app, a meaningful log message can help you to locate your issue quickly.

Don't

Do:

7. Consider to make it as a plugin instead of using Bean Shell

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.

8. Reuse existing plugins in your code to make it cleaner and easy to maintain

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: 

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

 

More samples

  • No labels