You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 11 Next »

Introduction

Workflow variables in Joget are key data elements that are essential for the overall operation and flow of a process. Unlike data specific to individual forms or activities, workflow variables have a broader scope and are used throughout the entire process. 

Distinction between normal data and workflow variables

For example, consider a Leave Application process. When an employee fills out a leave application form, they provide details such as the date of application, the duration of the leave, and the reason for the leave. This type of data is specific to that particular form. These details are critical for record-keeping and for informing the decision-makers (like supervisors) about the leave request. However, they typically serve only within the scope of that form and are used for informational purposes rather than driving the process flow. This form-specific data is usually stored associated with that particular leave application instance. It can be accessed and reviewed by relevant parties, such as HR personnel or supervisors, to understand the specifics of the leave request.

Workflow variables, on the other hand, are elements that carry significant weight in determining the flow of the process. In the Leave Application process, a good example of a workflow variable could be "supervisorApproval". This variable might store a value like "approved" or "rejected". The value of this variable is used to decide the next steps in the workflow. For example, if "supervisorApproval" is "approved", the process might move to the HR department for final processing. If it's "rejected", the process might end or return to the employee for further action. The key here is that the workflow variable directly influences the overall process flow. It's not just a piece of information, but a driver for decisions and actions within the workflow.

This variable becomes crucial when a supervisor's decision (accept or reject) alters the course of the workflow, triggering different activities or decisions.

Here is a screenshot from a sample app showing a process builder and workflow variable initialization.

Figure 1: Process Builder and Workflow Variable

Form Fields and Workflow Variables in Joget

Form Fields

Purpose and Usage: Form fields in Joget are primarily designed for user input and data display within a specific form. They are the interface elements that users interact with, such as text boxes, dropdowns, or date pickers. 

Scope: The data entered or displayed in form fields is specific to that form instance. It's used for capturing and displaying information relevant to a single step or part of the process. 

Storage: Data from form fields is typically stored in the application's database and is associated with the specific instance of the form. It's accessible whenever the form is loaded or referenced. 

Workflow Variables in Joget 

Their primary role is to facilitate decision-making and condition handling within the workflow in the process builder. 

Scope: Unlike form fields, workflow variables have a process-wide scope. They maintain their values across different forms and activities in a workflow, making them ideal for passing data between steps in a process. 

Influence on Process Flow: Workflow variables are often used to control process routing, conditions, and decision points within a workflow. Their values can determine which path a process takes, or which activities are triggered next. 

In Joget, a form field and a workflow variable, even if named similarly (e.g., both called "status"), are distinct entities. A form field is specific to a form and is used to capture user input, while a workflow variable is a broader process-level variable that can influence and guide the workflow's progression and routes taken. So in this case, the 'status' variable is also stored in different database tables.

Storage: Stored on a database table separate from the form data. These variables are stored in the "shkactivitydata" database table and are not to be tampered with for reasons mentioned below in the section (Storage mechanisms for form data variables and workflow variables).

Key Concepts

Hash Variables

In Joget, a Hash Variable is a specialized, hash-escaped keyword that has a wide range of applications across different components of the platform. It can be used in the Form Builder, List Builder, and UI Builder to dynamically retrieve and display the values of runtime variables. Beyond these builders, Hash Variables are also utilized in configuring properties for supported plugins, naming activities within the Process Builder, and specifying external form URLs when mapping activities to external forms.

Example- #date.D-MMM-yyyy# (date hash variable).

This versatile functionality allows Hash Variables to effectively pull and display relevant runtime information from the application's variables, enhancing the dynamic interaction and responsiveness of the application to real-time data changes.

It is recommended to read this article to have a clearer understanding of what hash variables are.

A hash variable is not to be confused with a workflow variable. Workflow variables can be 'extracted' or used as a hash variable for dynamic purposes (Workflow Assignment Hash Variable & Workflow Process Hash Variable).

Populate Data dynamically

For functionalities like populating an email body, both form data (accessed via # form.table.status #) and workflow variables (# variable.status #) can be utilized, offering flexibility in how data is referenced within the workflow.

Please do keep in mind that it is important to not confuse the form data with workflow variables. As explained before, they are separate entities but both entities can be used as hash variables for use inside, for example, an email body.

Update Mechanisms

Form Data Update Tool: This plugin is used to update values directly in the database. The changes made using this tool affect the data stored in form fields. It is an efficient way to ensure that the data entered or modified in form fields is accurately reflected in the database. Oftentimes, this will come inbuilt with your Joget version.

Workflow Variable Update Tool: Available at the marketplace, the Workflow Variable Update Tool updates the value of workflow variables. It's used when there's a need to modify the values of variables that control or influence the workflow process. If your goal is to match the form data variable with the workflow variable, it is necessary to use both the plugins mentioned above otherwise it will not synchronize properly if both of these tools are not used together.

Besides the Workflow Variable Update plugin, BeanShell scripting can also be used to update workflow variables. BeanShell is a lightweight scripting language that offers a flexible way to write scripts for various purposes, including updating workflow variables. While BeanShell scripting provides a powerful and flexible way to manage workflow variables, the Workflow Variable Update Tool is often preferred for its user-friendliness and ease of use, especially for users who might not be comfortable with scripting.

It only takes a couple of lines of code to set the value into a workflow variable:

import org.joget.workflow.model.service.*;

WorkflowManager wm = (WorkflowManager) pluginManager.getBean("workflowManager");
wm.activityVariable(workflowAssignment.getActivityId(),"status", "Approved");

Process Routing Mechanisms 

Form Data and Hash Variables for Routing

While workflow variables are essential for process routing, other elements like form data and hash variables can also be used for similar purposes. For example, using a form hash variable in a transition condition ((# form.f1.TextField # === "true")) is a viable alternative. Both form hash and workflow hash will work. Apart from routing, a workflow hash can also be used within the application for dynamic data referencing, such as in custom scripts or email bodies, where they can be called upon using syntax like # variable.status #.

A key feature of workflow variables is their ability to create an audit trail. As the process progresses, every change in the value of a workflow variable is recorded. This provides a detailed history of how the process has evolved over time, which is essential for review and monitoring purposes. This tracking ability enhances transparency and accountability in the workflow. By having a clear record of all changes, administrators and users can understand the decision-making process and the flow of activities more comprehensively.

Choosing the Right Tool

The decision to use workflow variables, form data, or hash variables depends on the specific needs of the process. For simpler decision-making where an audit trail is not critical, form data or hash variables might suffice. However, for complex processes where tracking the history of decisions is important, workflow variables become indispensable.

Storage mechanisms for form data variables and workflow variables

Workflow variables and form data in Joget serve different purposes but can be interconnected for efficient process management. Workflow variables are primarily used within the process flow. They are crucial for decision-making and guiding the direction of the workflow. Unlike form data, which is directly inputted by users into forms and inherently visible, workflow variables operate in the background and are not automatically displayed in forms or datalists.

The storage and display of workflow variables pose certain challenges. These variables are stored in the "shkactivitydata" database table. Displaying them in a datalist typically requires an SQL JOIN with this table. However, this can lead to performance issues, particularly in large-scale applications. For example, a process with numerous variables and activities can result in a substantial number of records in the database, escalating rapidly with the number of transactions. This increase in data can significantly impact the performance of datalists. For example, if your process has 10 workflow variables and 10 activities, the total records stored in the DB table is 100 records, and if the total number of process transactions reaches 1,000, you will generate 100,000 records in the "shkactivitydata" table for just one process. If the combined total of processes in all your Joget app is 100 processes, this table will grow to 10 million.

As a best practice, it's recommended to map workflow variables to form fields. This mapping ensures the values of workflow variables are 'copied' to corresponding form fields at each activity, making them visible and accessible for later viewing in forms and datalists. This approach avoids the direct querying of the large "shkactivitydata" table, thereby optimizing performance.








  • No labels