How can I use http task respone status at next process node?

image
image

After http task execute, when http body return a string like ‘1’, I can use it to judge, but can’t use response status code to judge, how can I deal with it?

Thanks!

Docs say can directly use it.

Remember all the above execution variable names are prefixed by evaluated value of resultVariablePrefix. For example response status code can be accessed in another activity as task7.responseStatusCode. Here task7 is the id of the service task. To override this behavior, set resultVariablePrefix as required.

I have resolved it, at v6.1.2, there is is bug, can’t rightly get response result variables. I can get it after modify source code, then I noticed github code has been update, but not publish a version. github commit: https://github.com/flowable/flowable-engine/commit/d7554ebb572caa7e66933852362610041baefecc#diff-d66c51ccebf7d3aff06bc6143c8f7bf8

Use taskResponseStatusCode! No task.responseStatusCode!

1 Like

Hi, sorry to bother you, can you tell me how you get the result variable?
I’ve set the parameters as you in the image, but if I print the process variables the response variable name is not there (in your case is hrResponse). Do you have the code to do this? I’m stuck and can’t find any example. Thank you

Hey @infiniteloop,

You can read more about the Http Task result variables here in the Flowable documentation. By default the response parameters are not saved into variables. In order to do that you would need to set the saveResponseParameters flag to true. You can read more about the Http Task configuration here.

Cheers,
Filip

Hi @filiphr , I had a look at the docs but I can’t make it work. I do not have saveResponseParameters flag in the http task, I only have Save response status, headers that I’ve set to true. Only other flag I have for response is Save response as JSON . I’ve specified Response variable name, one time with $ prefix and one other without, but I can’t retrieve it. Where should I find this variable and how should it be retrieved?

@infiniteloop can you perhaps share your BPMN XML so we can have a look at it?

Are you talking now about the Flowable UI Modeler?

You need to specify the resultVariablePrefix. If you don’t then the id of the task would be used for the variables.

Thank you @filiphr . This is my BPMN XML:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:flowable="http://flowable.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.flowable.org/processdef">
  <process id="Login" name="Login" isExecutable="true">
    <startEvent id="startEvent1"></startEvent>
    <serviceTask id="LoginTask" flowable:type="http">
      <extensionElements>
        <flowable:field name="requestMethod">
          <flowable:string><![CDATA[POST]]></flowable:string>
        </flowable:field>
        <flowable:field name="requestUrl">
          <flowable:string><![CDATA[https://reqres.in/api/login]]></flowable:string>
        </flowable:field>
        <flowable:field name="requestBody">
          <flowable:string><![CDATA[{"email": "peter@klaven" , "password" : "cityslicka"}]]></flowable:string>
        </flowable:field>
        <flowable:field name="responseVariableName">
          <flowable:expression><![CDATA[${status}]]></flowable:expression>
        </flowable:field>
        <flowable:field name="saveResponseParameters">
          <flowable:string><![CDATA[true]]></flowable:string>
        </flowable:field>
  <flowable:field name="resultVariablePrefix">
      <flowable:string><![CDATA[test]]></flowable:string>
    </flowable:field>
      </extensionElements>
    </serviceTask> 
</definitions>

And yes, I’m talking about the UI Modeler since I create my XMLs there.
I’ve specified the resultVariablePrefix as “test”, anyway I’m missing how to retrieve this variable. I’ve tried to print process variables but it isn’t there, and I couldn’t find any example where the variable is retrieved

Ps the variable “status” where the result should be is now written like that, but it’s not the only way I’ve tried

Please read the HTTP Task documentation. All parameters are explained there in detail.

The responseVariableName would be the name of the variable where the result of the HTTP call would be stored. If you use ${status} then the expression would be resolved to fine the name of the variable. In your case you want to use status only.

The resultVariablePrefix is the prefix for the execution variable names. So in order to get the response status code you would use testResponseStatusCode (in your example).

As I said, I’ve tried also with different syntax for status, even just the name as you suggested, but the variable is not present in the process variables. I’m not printing that variable only, I’m printing the map of all the process variables, and I’m not finding any testReponseStatusCode or status code at all in the variables :\

Hi @filiphr,

I followed your advice, but it’s still null.

I attached the sreenshoot modeler:

I attached the screenshoot postman response:
image

The configuration below works properly:

Hey @budi,

I don’t see a difference between the configuration that works and the one that doesn’t for you

Hi @filiphr,

The difference I give a red box.

Thanks @budi,

I see it now. Yes you need to explicitly say that you want to store that