Passing Task Variables to Process Variables

So I have a workflow that’s got a coupe pathways to take depending on what a user chooses to do. There’s a taskLocalVariable, called “action” that is set to either be approved or declined. If approved, I want the workflow to proceed to the next step. Declined moves the workflow to a prior step. I’m trying to transfer the “action” into a process variable so that I can use a conditional gateway to manage this behavior. The problem I’m having is that while I have a task listener set up, it’s proving hard to figure out how to do this.

This expression

${ execution.setVariable( ‘lastAdoAction’, ‘goober’ ) }

in the task listener works just fine. But if I try to actually get a hold of the “action” variable of the task, I’m not able to access it (comes back null). Reading around in the docs it sounds like this is a situation where I need a script task listener, but that’s not an option I can select using the eclipse designer. Do I need to go in and edit the BPMN file manually to get the task listener inserted, or do I really need to start writing the delegate task objects and attach them to the class path?

I’m not sure if I understand your question, but I’m gonna try to answer.

A example of decisions can be found in this excellent tutorial:

An example of a script executionListener. From the modeler you can download the xml and modify it in a text editor. Afterwards just import it again.

	<serviceTask id="GetReleaseVersions" name="GetReleaseVersions"
		flowable:type="http">
		<extensionElements>
			<flowable:field name="requestMethod">
				<flowable:string><![CDATA[GET]]></flowable:string>
			</flowable:field>
			<flowable:field name="requestUrl">
				<flowable:expression><![CDATA[http://rmt3.newtec.eu/rmt-web/node/children/${cboProductsResult}?token=cBaqMmeGjm]]></flowable:expression>
			</flowable:field>
			<flowable:field name="saveRequestVariables">
				<flowable:string><![CDATA[true]]></flowable:string>
			</flowable:field>
			<flowable:field name="resultVariablePrefix">
				<flowable:string><![CDATA[releases]]></flowable:string>
			</flowable:field>
			<flowable:executionListener event="end"
				class="org.flowable.engine.impl.bpmn.listener.ScriptExecutionListener">
				<flowable:field name="script">
					<flowable:string><![CDATA[
								
						responseBody = execution.getVariable("a"); 							
			            var b = a++

						execution.setVariable("b", b);
						]]>
					</flowable:string>
				</flowable:field>

				<flowable:field name="language">
					<flowable:string><![CDATA[javascript]]></flowable:string>
				</flowable:field>
			</flowable:executionListener>
		</extensionElements>
	</serviceTask>

An example of using java code: https://www.flowable.org/docs/userguide/index.html#_getting_started

1 Like

Yeah, this is exactly the help I needed. Between the tutorial and the script example you included, I should be able to get off the ground and functional. Thanks.