Have created a Flowable process which calls an external RESTFul API (from the Service task , implemented by a JavaDelegate). Am executing this process using another REST call i.e. Someone calls Flowable process using RESTful call and this Flowable process executes another External REST API call. My question is how can I pass the data which I get back from External REST call , back to the person who is calling Flowable REST call.
The easiest way would be to set process variables while executing the process instance, and when the process instance is completed, the Flowable REST service can get the process variables that are needed for the response and send the result back to the caller.
Thanks @tijs for replying. Can you also explain, as how should I get the handle to ProcessInstance in my Service class (which extends JavaDelegate). If I try to do something like :-
Then it triggers another instance of my process, as “startProcessInstanceById” would trigger it. My Service class is getting triggered by Flowable Engine and I don’t want to trigger it again. Please tell me , how can I get a handle to the ProcessInstance where I can store the variable to be sent back as part of the REST call response.
I tried to user ResultVariable in the ServiceTask to store and return the output but got the following Exception:-
result-var-name-with-delegate’] : ‘resultVariableName’ not supported for se
tasks using ‘class’ or 'delegateExpression - [Extra info : processDefiniti
= myProcess | processDefinitionName = API POST Call process | | id = callR
I | | activityName = Call REST API-POST call | ] ( line: 5, column: 159)
Looks like ResultVariables are not meant for this thing. Am still struck, as how to return a value to the Person calling my Process through REST client.
In the service task you can set the variables you want to sent back to the REST service caller as a process variable using execution.setVariable(“yourVarName”, “yourVarValue”); , Then when you get the ProcessInstance back from the startProcessInstanceById method you can cast it to ExecutionEntity and use the getVariables method to get the process variables from the process instance context and fill your REST response.
As I mentioned earlier, am not starting the process by calling startProcessInstanceById () method. I have deployed the process on Flowable usning the bpmn xml through Flowable UI (Flowable-modeler/task) and then I trigger it using Flowable-rest. The request and response for the Flowable-rest looks like this :-
Ok thanks, now I understand the issue.
This needs to be fixed. Will make sure any variables that are present in the ProcessInstance instance will be returned by the REST API as well.
Thanks @tijs. By when can I expect this fix to be rolled out ?
Is there any other way, I can return the values back from my ServiceTask . I am trying to explore adding a ScriptTask to the process and add header in the response (where ScriptTask would get the value passed from ServiceTask), but even that isn’t working . Please advice if you have any other solution to my problem.
Thanks @tijs adding “returnVariables” to the request has yielded the needed response.
Can you get the Flowable documentation (http://www.flowable.org/documentation.html) updated for this ?