REST Connector result expression can't access process instance variables


I am trying to merge the result of a REST connector call, with the process instance variables of the flow. From all experiments I tried, it seems, that the “Result expression” field, can’t access the process instance variables, or if there is a special way to refer the process instance variables there, then it is not obvious, and is not documented anywhere.

I am using Self Managed architecture, with 8.5.0 version.

This is the json I am initializing the process with. The CustomerFull is the object i try to access from the result expression, and want to merge the result into (later on, after i can access it).

“CustomerFull”: {
“CustomerPersonal”: {
“firstName”: “TEST”,
“dob”: “1977-11-27”,
“language”: “ENG”,
“lastName”: “test”,
“email”: “”,
“gender”: “M”
“CustomerLiab”: {
“liabilityCurrency”: “HUF”,
“liabilityName”: “12345678”,
“overlimit”: “9999999”
“name”: “TESTO002”,
“city”: “TESTADDRESS003”,
“street”: “HUHU”,
“media”: “MAIL”,
“shortName”: “Test039”,
“location”: “CIF”,
“nationality”: “HU”,
“fullName”: “Test Test”,
“country”: “HU”

Attached the bpmn file. In the result expression field I included some of the tried expressions (not all), for accessing the process instance variable, with no result. In the “Request body” field, i have no problem accessing the process variables.

diagram_1.bpmn (5.6 KB)

Thanks for he help and response in advance!

Hi @p_david, welcome to the forums! You are correct, and this is by design. The reason is that the result expression is evaluated in the Connector Runtime, not in the engine. The best thing to do is to use the output mapping to take what you’ve put into the result expression and manipulate/combine it further. Another option is to have a script task after the REST Connector task.

Hello @nathan.loding,

Thank you for your response.

I want to make sure I understand your explanation correctly. In the “result expression” field of the Rest connector task in the modeler, the label says “Expression to map the response into process variables”, so I believe this field is intended for mapping the response into process variables. When you mentioned “use the output mapping,” I assumed you could only be referring to was using the syntax described in the linked “Output mapping” section. Because, to me, the “result expression” field should handle the mapping of the output.

Regarding my attempts with the syntax on the website (e.g., {CustomerFull.customerNumber:body.CreateCustomerResponse.customerNumber}), I encountered a couple of issues. If the object already exists in the process variables (like CustomerFull here), the additional property (customerNumber) is not added to it. However, if it references a not-yet-created object (e.g., {ABCD.customerNumber:body.CreateCustomerResponse.customerNumber}), then the ABCD object is not created either. Instead, only a string is added to the process variables “ABCD.customerNumber,” and the object structure is not created or merged with the original object.

As for your suggestion to use a script task, that could work. However, I’m generating the REST connectors from parameters, and I would prefer to do the response mapping/merging to the process variables within that task and would not want to generate another script task aswell.

Could you possibly provide an example of the output mapping you referred to? I believe I’ve tried everything I could find on the site. Also, could you explain how the “Output mapping” should function? My understanding is that it should create the object structure if it doesn’t exist (e.g., a.b.c{a:{b:{c}}}), and if an object already exists, it should add the parameter to it (e.g., existing {a:{b}} + a.b.c{a:{b:{c}}}).

Thanks in advance for your help.

Best regards, David

@p_david - good questions! I’ll try my best to answer them while keeping it short, so let me know what other questions you might still have.

The result expression takes the data from the REST response and maps it to a new process variable (or overwrites the value of an existing variable). Because the FEEL expression is evaluated in the Connector Runtime, you cannot reference other process variables in the expression.

The output mapping happens after the task execution is complete. At this point, the result expression has been evaluated and mapped to a process variable, and should be available to use in the output mapping.

The mappings use FEEL, so if you want to combine objects (called contexts in FEEL), you need to use a FEEL function. There’s a few different ways to handle it, but one way might be use to the merge function: Context functions | Camunda 8 Docs

Hope that helps!

Thanks for the reply!

I am still a bit confused where and how the mapping is being done. In the rest connector there is only one field (result expression) where i can write FEEL expression. But here, like you said, i can’t access process variables. Somehow i should wait for the response of the result expression, and map after, but where?

@p_david - oh my. That is entirely my fault, apologies! You are correct, there is no additional output mapping like there is on some other tasks. Let me talk with the engineers and get some additional details!

@p_david - I spoke with some of our engineers, and I wasn’t entirely hallucinating the output mappings! They are still part of the task, but the REST Connector element template now hides them. You have two supported options:

  • you can edit the BPMN XML manually to add the output mapping. Even though it is hidden from the Modeler UI, it will still be executed by Zeebe.
  • you can fork the REST Connector template and add the output mapping element back in so you can use it inside Modeler.

This is something the product team has been thinking about improving - both in the product and the docs - so this is good feedback for them! Let me know if you have more questions!

@nathan.loding Thanks for the looking into the problem!

Editing the XML manually will be the way for me, as right now i am creating the REST connector programmatically anyway, so adding some additional logic shouldn’t be that challenging. So I guess the output mapping format should look the same as in a Service Task?

I will try out how it works, and will write my experience here.

Thanks again for the help!

1 Like