Setting Workflow Variable Value in Process Tool Bean Shell

Introduction

Setting the value of a workflow variable in a Joget process is a frequent requirement. By using the Process Tool BeanShell script, you can dynamically assign values to workflow variables with just a few lines of code. This method allows you to automate decision-making and status updates in your workflows.

How does it work?

You will use the following code snippet in a BeanShell script to set a workflow variable value within a process. This script retrieves the WorkflowManager service and sets the specified variable's value.

import org.joget.workflow.model.service.*;
 
WorkflowManager wm = (WorkflowManager) pluginManager.getBean("workflowManager");
wm.activityVariable(workflowAssignment.getActivityId(),"status", "Approved");
  1. Import the necessary WorkflowManager service that handles workflow-related operations.
  2. Obtain the current activity ID using workflowAssignment.getActivityId().
  3. Assign the value "Approved" to the workflow variable "status".

Note: Ensure that the workflow variable name ("status") matches exactly with the name you've defined in your process.

Once implemented, this script will automatically update the workflow variable when the activity is executed, streamlining the decision-making process and allowing for more dynamic workflows.

Important
Instead of using a BeanShell script, you can use the Workflow Variable Update Process Tool, which is available for free in the Joget Marketplace. This tool provides a simpler, code-free method for updating any number of workflow variables in your process.

Related documentation

Created by Julieth Last modified by Aadrian on Dec 13, 2024