How to take gateway decisions based on a Json Response

Hi All,

Please refer my following bpmn diagram.

image

Here getData service task implanting a http-connector and its getting a response like.

{ "GUID": "?", "Status":"Ok", "Error description":"?" }

I just want to check this status condition through a gateway task, probably using an expression. and if the Status Ok select a one path and if not other path.

Get data implementation like this.

Gateway expression like.

Can anyone help me on this?

Hey @Dasun ,

I if you want to use an Expression on the JSON you should include Spin. You would need to add Spin as dependency to your pom file and then you can use it to access the variables inside the JSON.
${S(response).prop("Status")}

I would use the expression to save this as an output parameter from the connector and then at the gateway you can use the saved output parameter to evaluate the XOR gateway.

I hope this helps
Kind regards
Nele

Hi @Nele ,

This is what i have implemented from the code level to accept JSON payload and execute above BPMN. But each service task has its connector implementations through the modeler like url,methos,payload likewise. So at that time how can i set a variable like you mentioned?

 ObjectMapper objectMapper = new ObjectMapper();
        String json = objectMapper.writeValueAsString(jsonObject);
        runtimeService.createMessageCorrelation(workFlowName)
                .setVariable(workFlowName, json)
                .correlate();

Hey @Dasun ,

I am a little bit confused by your code. Where do you use it (I thought you use connectors for your service task implementations?) and why does it contain a message correlation?

I am not 100% sure what you want to achieve. Could you maybe share your BPMN diagram?

Kind regards
Nele

Hi @Nele

Yes I can, This is only the process implementation.

image

getData service task connector implementation.

Condition check expression.

Thanks.

Hey @Dasun,

If you upload it as bpmn file I can inspect the connector better.
Do I understand it correctly that the evaluation at the XOR gateway is currently failing?

Kind regards
Nele

Hi @Nele

Here is the file,

sample.bpmn (7.9 KB)

In that file getData service task has a http-connector implementation and that REST call will return a Json response. What i want is to if Status = OK flow goes to lm service task and if Fail then process will be end.
JSON response be like

{ "GUID": "?", "Status":"Ok", "Error description":"?" }

Hey @Dasun,

The problem in your model are the data formats. Your lm_response is stored as a String. Hence the XOR Gateway can’t evaluate the expression afterwards.

Make either sure to use the Spin Extension to store the output as an Object to use Spin already in the output parameters to just store the information about the Status. I hope that helps.

Kind regards
Nele