Force Transition

Syntax

	forceTransition($processInstance, $targetTask)

Description

Forces a process instance to transition to a specific task. This method allows direct manipulation of the workflow state by bypassing normal flow controls. It should be used with caution.

Parameters

Process name Type Type Description Mandatory Default
processInstance ProcessExecution The process instance whose state should be modified. Yes -
targetTask Task The target task node where the new token should be created. Yes -

Return value

Type: Boolean

Returns true if the token transition was successful. Returns false if the operation failed, e.g., due to invalid arguments or if no active tokens exist in the process instance.

Examples

	//lets say we have a process with 4 Tasks: Submitted, InProgress, Review, Closed
//The normal flow would be:
// Submitted -> InProgress -> Review -> Closed
//But sometimes we need to skip steps and force a processInstance directly to Closed
//This example shows how to move a process from Submitted directly to Closed,
//bypassing both InProgress and Review tasks.
//Here's how we can do this: 

// First create a process instance with a specific name
processInstance = createProcessInstance($startEvent, "Process-001");

// Find the Closed task in our workflow definition
closedTask = all(`tl.bpe.bpml:Participant`)
    // Find the matching participant (workflow)
    .filter(p -> $p.get(`tl.bpe.bpml:Participant#name`) == $processName)
    // Get the single matching participant
    .singleElement()
    // Get its process
    .get(`tl.bpe.bpml:Participant#process`)
    // Get all nodes
    .get(`tl.bpe.bpml:Process#nodes`)
    // Filter out the Closed task
    .filter(n -> $n.get(`tl.bpe.bpml:Node#name`) == "Closed")
    .singleElement();

// Force the process to move directly to the Closed task, skipping InProgress and Review
forceTransition($processInstance, $closedTask)