define expression in camunda

4.4k Views Asked by At

I have a process that has a custom model, similar to the following model(get by calling http://localhost:8080/engine-rest/task/{id}/variables/):

{
    "Title": {
        "type": "String",
        "value": "aaa",
        "valueInfo": {
          
        }
      },
    "247f3af4-36cf-72cc-1a95-601f07640674": {
        "type": "String",
        "value": "{\"Title\":\"AA\",\"Value\":\"BB\"}",
        "valueInfo": {
      
        }
    }
}

I want to define a expressions at the gates. How should I do this?

I try these:

${ "247f3af4-36cf-72cc-1a95-601f07640674".Value == "AA"}

Or

${ JSON("247f3af4-36cf-72cc-1a95-601f07640674").prop("Value") == "AA"}

Or

${S(247f3af4-36cf-72cc-1a95-601f07640674).prop("Value").stringValue() == "AA"}

But get following errors:

Unknown property used in expression: ${ "247f3af4-36cf-72cc-1a95-601f07640674".Value == "AA"}. Cause: Could not find property Value in class java.lang.String
Error while evaluating expression: ${ JSON("247f3af4-36cf-72cc-1a95-601f07640674").prop("Value") == "AA"}. Cause: Error invoking function 'JSON'
ENGINE-01009 Error while parsing process. Error parsing '${S(247f3af4-36cf-72cc-1a95-601f07640674).prop("Value").stringValue() == "AA"}': syntax error at position 15, encountered 'c7', expected ')'.

enter image description here

2

There are 2 best solutions below

0
On BEST ANSWER

I finally find answer I must use something like this:

${S(a247f3af4_36cf_72cc_1a95_601f07640674).prop("Value").stringValue() == "AA"}

we must start variable name with character and do'nt use -.

3
On

What you are showing is the value of a JSON object stored in a process data, right? What is the name of the process data?

In Java you use JSON(), in the process (JavaScript) use S() (see https://docs.camunda.org/manual/7.17/reference/spin/json/01-reading-json/)

Place S() around the name of your process data to create the object. Then you can use .prop() to navigate it. ${S(myData).prop("xyz")}.

In this example I used the method to read the JSON response of a REST call and then extract a field:

https://github.com/rob2universe/camunda-http-connector-example

You use JSON() around the name of the process data, then you can access the properties