0

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

Amir133
  • 2,372
  • 2
  • 18
  • 34

2 Answers2

0

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

rob2universe
  • 7,059
  • 39
  • 54
  • yes this is the value of a JSON object stored in a process data and get it by calling `http://localhost:8080/engine-rest/task/{id}/variables/`. But what is the `name of your process data` ? – Amir133 Apr 19 '22 at 10:00
  • please see this image : https://i.stack.imgur.com/Cn3lJ.png – Amir133 Apr 19 '22 at 10:31
  • The {id} you use when using: ttp://localhost:8080/engine-rest/task/{id}/variables/. Under which identifier to you store the data? – rob2universe Apr 19 '22 at 22:14
-1

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 -.

Amir133
  • 2,372
  • 2
  • 18
  • 34