API: process
Source:
bpm/process.ts
API Process
- Provides methods for interacting with process instances, including starting, updating metadata, and managing variables.
Usage
// manipulating process variables throughout the execution context
import { process } from "sdk/bpm";
// Hello from the Enterprise Javascript delegate
console.info("Hello from the Javascript Engine!");
let execution = process.getExecutionContext();
process.setVariable(execution.getId(), "variable2", "value2");
try {
console.info("variable1: " + process.getVariable(execution.getId(), "variable1"));
console.info("variable2: " + process.getVariable(execution.getId(), "variable2"));
} catch (e) {
if (e instanceof Error) {
console.error(e.message);
} else {
console.error("Something went wrong", e)
}
}Classes
Process
API Process
* Provides methods for interacting with process instances,
including starting, updating metadata, and managing variables.
Methods
start
start (key:string, businessKey:string='', parameters:{[key:string]:any}={}):stringStarts a new process instance for a given process definition key.
@param key The process definition key (ID) of the process to start.
@param businessKey An optional business key to associate with the process instance. Defaults to an empty string.
@param parameters An optional map of process variables to pass to the process instance upon starting. Defaults to an empty object.
@returns The unique ID of the newly started process instance.
setProcessInstanceName
setProcessInstanceName (processInstanceId:string, name:string):voidSets a human-readable name for an existing process instance.
@param processInstanceId The ID of the process instance to update.
@param name The new name for the process instance.
updateBusinessKey
updateBusinessKey (processInstanceId:string, businessKey:string):voidUpdates the business key of an existing process instance.
@param processInstanceId The ID of the process instance to update.
@param businessKey The new business key.
updateBusinessStatus
updateBusinessStatus (processInstanceId:string, businessStatus:string):voidUpdates the business status of an existing process instance.
@param processInstanceId The ID of the process instance to update.
@param businessStatus The new business status.
getVariable
getVariable (processInstanceId:string, variableName:string):anyRetrieves the value of a specific variable from a process instance.
@param processInstanceId The ID of the process instance.
@param variableName The name of the variable to retrieve.
@returns The value of the variable, ornullif the variable does not exist. The type isanyas it depends on the stored value.
getVariables
getVariables (processInstanceId:string):anyRetrieves all variables associated with a process instance.
@param processInstanceId The ID of the process instance.
@returns An object containing all variables for the process instance, where keys are variable names and values are the variable values.
setVariable
setVariable (processInstanceId:string, variableName:string, value:any):voidSets or updates the value of a variable in a process instance.
@param processInstanceId The ID of the process instance.
@param variableName The name of the variable to set.
@param value The new value for the variable. The type isanyto accommodate different data types.
removeVariable
removeVariable (processInstanceId:string, variableName:string):voidRemoves a variable from a process instance.
@param processInstanceId The ID of the process instance.
@param variableName The name of the variable to remove.
correlateMessageEvent
correlateMessageEvent (processInstanceId:string, messageName:string, variables:Map<string, any>):voidCorrelates a message event with a running process instance.
@param processInstanceId The ID of the process instance to correlate the message to.
@param messageName The name of the message event defined in the BPMN process.
@param variables A map of variables (Map<string, any>) to pass along with the message event.
getExecutionContext
getExecutionContext ()voidRetrieves the current execution context object, typically used within an execution listener or service task.
@returns A new instance of theExecutionContextcontaining details about the current process execution path.
ExecutionContext
ExecutionContext object
* Provides detailed information and control over the current process execution path.
Methods
getId
getId ():stringUnique id of this path of execution that can be used as a handle to provide external signals back into the engine after wait states.
@returns The unique ID of the current execution.
getProcessInstanceId
getProcessInstanceId ():stringReference to the overall process instance.
@returns The ID of the process instance.
getRootProcessInstanceId
getRootProcessInstanceId ():stringThe 'root' process instance. When using call activity for example, the processInstance set will not always be the root. This method returns the topmost process instance.
@returns The ID of the root process instance.
getEventName
getEventName ():stringWill contain the event name in case this execution is passed in for an {@link ExecutionListener}.
@returns The current event name, ornull/empty string if not executing an event listener.
setEventName
setEventName (eventName:string):voidSets the current event (typically when execution an {@link ExecutionListener}).
@param eventName The name of the event.
getProcessInstanceBusinessKey
getProcessInstanceBusinessKey ():stringThe business key for the process instance this execution is associated with.
@returns The business key.
getProcessInstanceBusinessStatus
getProcessInstanceBusinessStatus ():stringThe business status for the process instance this execution is associated with.
@returns The business status.
getProcessDefinitionId
getProcessDefinitionId ():stringThe process definition key for the process instance this execution is associated with.
@returns The process definition ID.
getPropagatedStageInstanceId
getPropagatedStageInstanceId ():stringIf this execution runs in the context of a case and stage, this method returns it's closest parent stage instance id (the stage plan item instance id to be
precise).
@returns The stage instance id this execution belongs to ornull, if this execution is not part of a case at all or is not a child element of a stage.
getParentId
getParentId ():stringGets the id of the parent of this execution. If null, the execution represents a process-instance.
@returns The parent execution ID, ornull.
getSuperExecutionId
getSuperExecutionId ():stringGets the id of the calling execution. If not null, the execution is part of a subprocess.
@returns The super execution ID, ornull.
getCurrentActivityId
getCurrentActivityId ():stringGets the id of the current activity.
@returns The current activity ID.
getTenantId
getTenantId ():stringReturns the tenant id, if any is set before on the process definition or process instance.
@returns The tenant ID, ornull/empty string.
getCurrentFlowElement
getCurrentFlowElement ():anyThe BPMN element where the execution currently is at.
@returns The current flow element object (type is Java object).
setCurrentFlowElement
setCurrentFlowElement (flowElement:any):voidChange the current BPMN element the execution is at.
@param flowElement The new flow element object (Java type).
getCurrentFlowableListener
getCurrentFlowableListener ():anyReturns the {@link FlowableListener} instance matching an {@link ExecutionListener} if currently an execution listener is being execution. Returns null otherwise.
@returns The current Flowable Listener object (Java type), ornull.
setCurrentFlowableListener
setCurrentFlowableListener (currentListener:any):voidCalled when an {@link ExecutionListener} is being executed.
@param currentListener The current listener object (Java type).
snapshotReadOnly
snapshotReadOnly ():anyCreate a snapshot read only delegate execution of this delegate execution.
@returns A {@link ReadOnlyDelegateExecution} object (Java type).
getParent
getParent ():anyreturns the parent of this execution, or null if there no parent.
@returns The parent execution object (Java type), ornull.
getExecutions
getExecutions ():any[]returns the list of execution of which this execution the parent of.
@returns An array of child execution objects (Java type).
setActive
setActive (isActive:boolean):voidmakes this execution active or inactive.
@param isActive A boolean indicating whether the execution should be active.
isActive
isActive ():booleanreturns whether this execution is currently active.
@returnstrueif active,falseotherwise.
isEnded
isEnded ():booleanreturns whether this execution has ended or not.
@returnstrueif ended,falseotherwise.
setConcurrent
setConcurrent (isConcurrent:boolean):voidchanges the concurrent indicator on this execution.
@param isConcurrent A boolean indicating whether the execution should be concurrent.
isConcurrent
isConcurrent ():booleanreturns whether this execution is concurrent or not.
@returnstrueif concurrent,falseotherwise.
isProcessInstanceType
isProcessInstanceType ():booleanreturns whether this execution is a process instance or not.
@returnstrueif it's a process instance,falseotherwise.
inactivate
inactivate ():voidInactivates this execution. This is useful for example in a join: the execution still exists, but it is not longer active.
isScope
isScope ():booleanReturns whether this execution is a scope.
@returnstrueif it is a scope,falseotherwise.
setScope
setScope (isScope:boolean):voidChanges whether this execution is a scope or not.
@param isScope A boolean indicating whether the execution should be a scope.
isMultiInstanceRoot
isMultiInstanceRoot ():booleanReturns whether this execution is the root of a multi instance execution.
@returnstrueif it's a multi instance root,falseotherwise.
setMultiInstanceRoot
setMultiInstanceRoot (isMultiInstanceRoot:boolean):voidChanges whether this execution is a multi instance root or not.
@param isMultiInstanceRoot A boolean indicating whether the execution is the root of a multi-instance execution.
getVariables
getVariables ():Map<string,any>Returns all variables. This will include all variables of parent scopes too.
@returns A Map of variable names (string) to variable values (any).
getVariableInstances
getVariableInstances ():Map<string,any>Returns all variables, as instances of the {@link VariableInstance} interface, which gives more information than only the value (type, execution id, etc.)
@returns A Map of variable names (string) to {@link VariableInstance} objects (Java type).
getVariablesLocal
getVariablesLocal ():Map<string,any>Returns the variable local to this scope only. So, in contrary to {@link #getVariables()}, the variables from the parent scope won't be returned.
@returns A Map of variable names (string) to local variable values (any).
getVariableInstancesLocal
getVariableInstancesLocal ():Map<string,any>Returns the variables local to this scope as instances of the {@link VariableInstance} interface, which provided additional information about the variable.
@returns A Map of variable names (string) to local {@link VariableInstance} objects (Java type).
getVariable
getVariable (variableName:string):anyReturns the variable value for one specific variable. Will look in parent scopes when the variable does not exist on this particular scope.
@param variableName The name of the variable to retrieve.
@returns The value of the variable (any), ornullif not found.
getVariableInstance
getVariableInstance (variableName:string):anySimilar to {@link #getVariable(String)}, but returns a {@link VariableInstance} instance, which contains more information than just the value.
@param variableName The name of the variable to retrieve.
@returns The {@link VariableInstance} object (Java type), ornull.
getVariableLocal
getVariableLocal (variableName:string):anyReturns the value for the specific variable and only checks this scope and not any parent scope.
@param variableName The name of the local variable to retrieve.
@returns The value of the local variable (any), ornullif not found locally.
getVariableInstanceLocal
getVariableInstanceLocal (variableName:string):anySimilar to {@link #getVariableLocal(String)}, but returns an instance of {@link VariableInstance}, which has some additional information beyond the value.
@param variableName The name of the local variable to retrieve.
@returns The local {@link VariableInstance} object (Java type), ornull.
getVariableNames
getVariableNames ():Set<string>Returns all the names of the variables for this scope and all parent scopes.
@returns A Set of all variable names (string).
getVariableNamesLocal
getVariableNamesLocal ():Set<string>Returns all the names of the variables for this scope (no parent scopes).
@returns A Set of local variable names (string).
setVariable
setVariable (variableName:string, value:any):voidSets the variable with the provided name to the provided value. It checks parent scopes for an existing variable before setting on the current scope.
@param variableName The name of the variable to be set.
@param value The value of the variable to be set (any).
setVariableLocal
setVariableLocal (variableName:string, value:any):anySimilar to {@link #setVariable(String, Object)}, but the variable is set to this scope specifically (local variable).
@param variableName The name of the variable to be set locally.
@param value The value of the variable to be set (any).
@returns The old value of the local variable (Java type), ornull.
setVariables
setVariables (variables:Map<string, any>):voidSets the provided variables to the variable scope, using the default scoping algorithm.
@param variables A map of keys (string) and values (any) for the variables to be set.
setVariablesLocal
setVariablesLocal (variables:Map<string, any>):voidSimilar to {@link #setVariables(Map)}, but the variables are set on this scope specifically (local variables).
@param variables A map of keys (string) and values (any) for the local variables to be set.
hasVariables
hasVariables ():booleanReturns whether this scope or any parent scope has variables.
@returnstrueif variables exist in scope hierarchy,falseotherwise.
hasVariablesLocal
hasVariablesLocal ():booleanReturns whether this scope has variables.
@returnstrueif local variables exist,falseotherwise.
hasVariable
hasVariable (variableName:string):booleanReturns whether this scope or any parent scope has a specific variable.
@param variableName The name of the variable to check.
@returnstrueif the variable is found in the scope hierarchy,falseotherwise.
hasVariableLocal
hasVariableLocal (variableName:string):booleanReturns whether this scope has a specific variable.
@param variableName The name of the local variable to check.
@returnstrueif the variable is found locally,falseotherwise.
removeVariable
removeVariable (variableName:string):voidRemoves the variable from the process instance and creates a new HistoricVariableUpdate. Searches up the scope hierarchy.
@param variableName The name of the variable to remove.
removeVariableLocal
removeVariableLocal (variableName:string):voidRemoves the local variable and creates a new HistoricVariableUpdate.
@param variableName The name of the local variable to remove.
removeVariables
removeVariables (variableNames:string[]):voidRemoves the variables and creates a new HistoricVariableUpdate for each of them. Searches up the scope hierarchy.
@param variableNames An array of variable names (string[]) to remove.
removeVariablesLocal
removeVariablesLocal (variableNames:string[]):voidRemoves the local variables and creates a new HistoricVariableUpdate for each of them.
@param variableNames An array of local variable names (string[]) to remove.
setTransientVariable
setTransientVariable (variableName:string, variableValue:any):voidSets a transient variable using the default scoping mechanism (up the hierarchy). Transient variables have no history and are cleared at wait states.
@param variableName The name of the transient variable.
@param variableValue The value of the transient variable (any).
setTransientVariableLocal
setTransientVariableLocal (variableName:string, variableValue:any):voidSets a local transient variable. Transient variables have no history and are cleared at wait states.
@param variableName The name of the local transient variable.
@param variableValue The value of the local transient variable (any).
setTransientVariables
setTransientVariables (transientVariables:Map<string, any>):voidSets multiple transient variables using the default scoping mechanism (up the hierarchy).
@param transientVariables A map of keys (string) and values (any) for the transient variables to be set.
getTransientVariable
getTransientVariable (variableName:string):anyRetrieves the value of a transient variable, searching up the parent scopes.
@param variableName The name of the transient variable to retrieve.
@returns The value of the transient variable (any), ornullif not found.
getTransientVariables
getTransientVariables ():Map<string,any>Retrieves all transient variables in the current scope hierarchy.
@returns A Map of transient variable names (string) to values (any).
setTransientVariablesLocal
setTransientVariablesLocal (transientVariables:Map<string, any>):voidSets multiple local transient variables.
@param transientVariables A map of keys (string) and values (any) for the local transient variables to be set.
getTransientVariableLocal
getTransientVariableLocal (variableName:string):anyRetrieves the value of a local transient variable.
@param variableName The name of the local transient variable to retrieve.
@returns The value of the local transient variable (any), ornullif not found.
getTransientVariablesLocal
getTransientVariablesLocal ():Map<string,any>Retrieves all local transient variables.
@returns A Map of local transient variable names (string) to values (any).
removeTransientVariableLocal
removeTransientVariableLocal (variableName:string):voidRemoves a specific local transient variable.
@param variableName The name of the local transient variable to remove.
removeTransientVariable
removeTransientVariable (variableName:string):voidRemoves a specific transient variable, searching up the scope hierarchy.
@param variableName The name of the transient variable to remove.
removeTransientVariables
removeTransientVariables ():voidRemove all transient variables of this scope and its parent scopes.
removeTransientVariablesLocal
removeTransientVariablesLocal ():voidRemoves all local transient variables.