How to get Expression value by rest api?

Hi all,
There is a problem which perplex me a lot .When I pushed external task to the workflow engine , I want to get expression value via rest api , How can I do ?

Can you clarify a little bit about what you mean

Does this mean when you complete an external task from an external client?

What expression are you referring to and what use case do you have to retrieving the value?

At first , sorry for my delay for your reply and really thank you that you could solve my problem patiently .
Then I will describe my problem clearly .
I’m a front-end engineer(major Angular) and now I want to add workflow to my project . I found that Camunda is the most suitable workflow with many advantages . Let’s discuss a very simple use case , like this:
image
I create this diagram and the service task I choose “external”(node.js) to implement . The expression I mentioned is when I created this diagram I input some values like this:
image
I instantiate it and want to start this process instantiation . When it run “Play Basketball” I set process variables (weatherOk is true) to control path and finally arrive at “Have fun” .
The problem comes!!
I couldn’t find #{weatherOk} value in our API , so I created a popup in my project when I want to start process and I will input this value like “weatherOk” . I think this is not a common way to solve this problem , and hope that you can give me some new thinkings .
Really thank you for your help~ :slight_smile:

So it sounds to me like you’re not able to pass the variable from your external task to the engine.
Can you show me the code for your external task?

We have some examples of how variables can be passed from the task onthe client page.

const { Variables } = require("camunda-external-task-client-js");

client.subscribe("topicName", async function({ task, taskService }) {
  // get the process variable 'score'
  const score = task.variables.get("score");

  // set a process variable 'winning'
  const processVariables = new Variables();
  processVariables.set("winning", score > 5);

  // set a local variable 'winningDate'
  const localVariables = new Variables();
  localVariables.set("winningDate", new Date());

  // complete the task
  await taskService.complete(task, processVariables, localVariables);
});

Actually not … I can set the process variable and it worked . The problem is I want to get expression key via rest API and just set value to the key rather I need to input key and value like processVariables.set("weatherOk", true); I don’t know weather I made myself clearly or not .

I understand now what you’re interested in doing.
Why exactly do you need to do this?

Let’s imagine a situation , the diagram is deployed by other person and I don’t know this expression key and I just want to control this process path . I think I need to get this key …

Generally speaking this pattern could become very complex in future. In this case the variable that is created by the worked is used immediately afterwards but in a lot of cases a worker will create a bunch of variables that are maybe used much further down the line or maybe not by expressions but by other services so i don’t see this pattern working out in the long run.

Instead i would suggest looking at the input/output fields in which you can map the value returned by the external task to a process variable name that your expression is expecting. Then the expression and the returned value are not directly linked.

Ok , maybe I understand what you said . It means that in a complex use case , the user should set all variables which will make this path to the destination . Maybe I should try a complex use case to understand what you say . By the way , really thank you for your support and I think you are so kind ~:)

1 Like