Change Node - Not sure how to Reference payload in Expression

Hi,
Given the expression and input below using the Change node, the test function works fine however when running the trigger I get no output. I've looked at many other posts on here and suspect I am not properly referencing the payload but I cannot figure out how I should do that. I'm using v3.0.2

Input:

[
    {
        "Obj1": [
            {
                "Datetime": "2020-04-03 01:21:07.650",
                "ID": "00001",
                "code": "WAXXNNNX"
            },
            {
                "Datetime": "2020-04-03 01:21:07.650",
                "ID": "00002",
                "code": "CAXXNNNX"
            }
        ]
    },
    {
        "Obj2": [
            {
                "X102": "Y",
                "X116": "N",
                "X435": "00001"
            },
            {
                "X102": "Y",
                "X116": "Y",
                "X435": "00002"
            }
        ]
    }
]

Expression:

Obj1@$A.Obj2@$B[$B.X435=$string($A.ID)].{
  'ID': $A.ID,
  'Datetime': $A.Datetime,
  'Code': $A.Code,
  'X102_ZipSuffixFlag': $B.X102,
  'X116_TerminationIDFlag': $B.X116
}


2023-06-14_09-53-45

Flow Json/Code:

[
    {
        "id": "36dfb3f779a74351",
        "type": "tab",
        "label": "Flow 3",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "18696e4694de5bf1",
        "type": "inject",
        "z": "36dfb3f779a74351",
        "name": "Main",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "[     {         \"Obj1\": [             {                 \"Datetime\": \"2020-04-03 01:21:07.650\",                 \"ID\": \"00001\",                 \"code\": \"WAXXNNNX\"             },             {                 \"Datetime\": \"2020-04-03 01:21:07.650\",                 \"ID\": \"00002\",                 \"code\": \"CAXXNNNX\"             }         ]     },     {         \"Obj2\": [             {                 \"X102\": \"Y\",                 \"X116\": \"N\",                 \"X435\": \"00001\"             },             {                 \"X102\": \"Y\",                 \"X116\": \"Y\",                 \"X435\": \"00002\"             }         ]     } ]",
        "payloadType": "str",
        "x": 1270,
        "y": 60,
        "wires": [
            [
                "53fa8b28361c395f"
            ]
        ]
    },
    {
        "id": "53fa8b28361c395f",
        "type": "json",
        "z": "36dfb3f779a74351",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 1270,
        "y": 120,
        "wires": [
            [
                "b6fd2e4b79e75df8"
            ]
        ]
    },
    {
        "id": "b6fd2e4b79e75df8",
        "type": "change",
        "z": "36dfb3f779a74351",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "Obj1@$A.Obj2@$B[$B.X435=$string($A.ID)].{\t  'ID': $A.ID,\t  'Datetime': $A.Datetime,\t  'Code': $A.Code,\t  'X102_ZipSuffixFlag': $B.X102,\t  'X116_TerminationIDFlag': $B.X116\t}\t",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1280,
        "y": 180,
        "wires": [
            [
                "4038a268a78e5ff2"
            ]
        ]
    },
    {
        "id": "4038a268a78e5ff2",
        "type": "debug",
        "z": "36dfb3f779a74351",
        "name": "debug 13",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1260,
        "y": 240,
        "wires": []
    }
]

Try

$$.payload[0].Obj1@$Obj1.(
    $Obj2 := $$.payload[1].Obj2[$.X435 = $Obj1.ID];  
    {
        'ID': $Obj1.ID,
        'Datetime': $Obj1.Datetime,
        'Code': $Obj1.code,
        'X102_ZipSuffixFlag': $Obj2.X102,  
        'X116_TerminationIDFlag': $Obj2.X116
    }
)

Half your issue is that you have not set up test input correctly

Thank you.
Question: Is the need for a high level 'payload' object necessary because of JSONata, the way JSONata is executed within a node or some other reason? I'm trying to understand the underlying reason and it isn't clear to me. It is proper formatted JSON so why the need for a single root object in order to work correctly? This matters because I'll need to do extra work when combining various JSON documents before merging them and I'd like to know if it is always necessary and why it is necessary.
Thanks again!

Are we talking test or expression payload.

If test.
Your array is in payload in the change node, so needs to be in payload for test as base level is msg, and msg must always be an object.
If expression.
You could use wildcards * or ** instead of payload.

Thank you, I understand now. In order for the test input to work with the expression you specified in the test utility, there has to be a 'payload' object at the highest level to emulate how the message will be accessible in the node at run time. My input for the node to process at runtime can remain the same input in my initial post. This was not clear to me at first but now I understand the input must me modified only for the testing feature.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.