'define expression in camunda

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



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 rob2universe