From 20ff7b2c64865ff9a2cb651bf91e69e6e2a9104b Mon Sep 17 00:00:00 2001 From: Francisco Javier Tirado Sarti Date: Fri, 4 Oct 2024 17:08:57 +0200 Subject: [PATCH] [Fix #3694] Updating documentation $ rather than . should be used for loop variable --- .../core/understanding-jq-expressions.adoc | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/serverlessworkflow/modules/ROOT/pages/core/understanding-jq-expressions.adoc b/serverlessworkflow/modules/ROOT/pages/core/understanding-jq-expressions.adoc index 4bc255bcd..0fca5eea7 100644 --- a/serverlessworkflow/modules/ROOT/pages/core/understanding-jq-expressions.adoc +++ b/serverlessworkflow/modules/ROOT/pages/core/understanding-jq-expressions.adoc @@ -239,6 +239,59 @@ In the previous example, a CloudEvent was published when the state transitioned. data={"gitRepo":"ssh://bitbucket.org/m2k-test","branch":"aaaaaaasssss","token":null,"workspaceId":"b93980cb-3943-4223-9441-8694c098eeb9","projectId":"9b305fe3-d441-48ce-b01b-d314e86e14ec","transformId":"723dce89-c25c-4c7b-9ef3-842de92e6fe6","workflowCallerId":"7ddb5193-bedc-4942-a857-596b31f377ed"} ---- +== ForEach state + +ForEach `iteratiomParam` should be accessed as a variable, not as a JSON property, since the loop variable is not part of the workflow model the expression is evaluated against. This means that rather than prefixing the variable name with a `.`, it should be prefixed with a `$` + +For instance, this link:{spec_doc_url}#foreach-state[ForEach specification example] + +[source,json] +---- + "states": [ + { + "name":"SendConfirmState", + "type":"foreach", + "inputCollection": "${ [.orders[] | select(.completed == true)] }", + "iterationParam": "completedorder", + "outputCollection": "${ .confirmationresults }", + "actions":[ + { + "functionRef": { + "refName": "sendConfirmationFunction", + "arguments": { + "orderNumber": "${ .completedorder.orderNumber }", + "email": "${ .completedorder.email }" + } + } + }], + "end": true + }] +---- + +should be modified to + +---- + "states": [ + { + "name":"SendConfirmState", + "type":"foreach", + "inputCollection": "${ [.orders[] | select(.completed == true)] }", + "iterationParam": "completedorder", + "outputCollection": "${ .confirmationresults }", + "actions":[ + { + "functionRef": { + "refName": "sendConfirmationFunction", + "arguments": { + "orderNumber": "${ $completedorder.orderNumber }", + "email": "${ $completedorder.email }" + } + } + }], + "end": true + }] +---- + == Workflow secrets, constants and context