BUG? Input fields are both defined and not-defined, can't be accessed in code node

In the code node, the acts input field is accessible to console.log() as expected, but any attempt to reference it in the code gives an error claiming it is undefined… though console.log() has no trouble displaying it.

Hey @Matt_Blais,

Can you share the JSON output of the node before the code node and the code you are using to we can give it a test? I have done a quick test and it looks to be ok so I am wondering what I am missing.

1 Like

For context:


The current code in the “Combine WAction scripts” code node:

const scriptBefore = `const exec = {\n`
const scriptAfter = `}\n
const fibery = context.getService('fibery')
for (const action of args.currentEntities) {
    console.log(\`Action Name: "\${action.Name}"\`)
}
`
for (const item of $input.all()) {
  const acts = item.json.acts
  console.log( typeof acts, acts )
  console.log( acts[0] )
  // more code goes here eventually, adding new elements to "item"
}
return $input.all()

The current JSON input to the code node: (redacted)

[
  {
    "dbRules": {
      "lastRun": {
        "status": "NOT STARTED"
      },
      "name": "Execute: Web Page",
      "type": "AUTO",
      "enabled": true,
      "accountName": "*****.fibery.io",
      "ownerId": "f13af52d-dea3-40af-83dc-b41876015c00",
      "typeId": "*****************",
      "actions": [
        {
          "meta": {
            "name": "Script",
            "args": [
              {
                "id": "script",
                "type": "script",
                "name": "Script",
                "description": "Script code"
              }
            ]
          },
          "id": "*****************",
          "action": "script-4fe9df50-8355-11ee-b49b-3b031a8172e4",
          "args": {
            "script": {
              "type": "value",
              "value": "const fibery = context.getService('fibery')\nfor (const action of args.currentEntities) {\n    console.log(`Action Name: \"${action.Name}\"`)\n}"
            }
          },
          "ownerId": "f13af52d-dea3-40af-83dc-b41876015c00",
          "app": "fibery"
        },
        {
          "meta": {
            "name": "Update",
            "args": [
              {
                "id": "fields",
                "type": "fibery/fields",
                "name": "Fields",
                "meta": {
                  "typeId": "*****************" 
                },
                "description": "Select WAction fields you want to change"
              }
            ]
          },
          "id": "50522b4f-79a5-46a2-94d5-7eaf97443864",
          "action": "update-4fe9df50-8355-11ee-b49b-3b031a8172e4",
          "args": {
            "fields": {
              "type": "value",
              "value": {
                "672b1bc0-e1c9-47ba-9024-b7439eb17140": {
                  "type": "formula",
                  "value": {
                    "expression": [
                      "q/date-time",
                      "$formula-now-date-time-placeholder"
                    ],
                    "params": {
                      "$formula-now-date-time-placeholder": "$formula-now-date-time-placeholder"
                    }
                  }
                },
                "f30ce8f0-bb87-4dae-a5d8-557fb64f9812": {
                  "type": "empty"
                }
              }
            }
          },
          "ownerId": "f13af52d-dea3-40af-83dc-b41876015c00",
          "app": "fibery"
        }
      ],
      "triggers": [
        {
          "trigger": "updated",
          "app": "fibery",
          "args": {
            "updatedField": [
              "f30ce8f0-bb87-4dae-a5d8-557fb64f9812"
            ],
            "filter": {
              "filterExpression": [
                "and",
                [
                  "=",
                  [
                    "f30ce8f0-bb87-4dae-a5d8-557fb64f9812"
                  ],
                  "$where1"
                ],
                [
                  "q/contains",
                  [
                    "2a2e879a-c5a9-4e2d-8e70-62fdae2ff722"
                  ],
                  "$where2"
                ]
              ],
              "params": {
                "$where1": true,
                "$where2": "Web Page |"
              }
            }
          },
          "id": "*****************"
        }
      ],
      "created": "2023-11-30T21:45:24.629Z",
      "id": "****************"
    }
  },
  {
    "vars": {
      "FIBERY_DOMAIN": "******.fibery.io",
      "FIBERY_API_KEY": "*****************" 
    },
    "hBody": {
      "type": "Workflows/WAction",
      "space": "Workflows",
      "dbId": "*****************",
      "actions": [
        {
          "name": "Web Page | Approved",
          "action": "// This is the Approved action\n\nvar MyTask = this.WTask, MyWorkflow = this.Workflow"
        },
        {
          "name": "Web Page | Rewrite",
          "action": "// This is the Rewrite action\nvar MyTask = this.WTask, MyWorkflow = this.Workflow\n//Done"
        }
      ]
    },
    "acts": [
      {
        "name": "Web Page | Approved",
        "action": "// This is the Approved action\n\nvar MyTask = this.WTask, MyWorkflow = this.Workflow"
      },
      {
        "name": "Web Page | Rewrite",
        "action": "// This is the Rewrite action\nvar MyTask = this.WTask, MyWorkflow = this.Workflow\n//Done"
      }
    ]
  }
]

Can you please add console.log( JSON.stringify(acts[0], null, 2) )
before: console.log( acts[0] )
and then post that output. Thanks!

Same issue:

Very sorry, my mistake. I did mean:

console.log( JSON.stringify(acts, null, 2) )

Now there is NO OUTPUT in the debug console, but still the same error reported:

Hey Matt,

can you try to have the console.log output that Jan mentioned in front of the other one? It happend sometimes to me that a console.log call errored and that all console outputs afterwards were not showing.

@Niklas_Hatje - that did not change anything:

Sorry, we have pretty much no idea what is going on here. For that reason those strange requests. Can you please remove all console.log except the:

console.log( JSON.stringify(acts, null, 2) )

Are you able to create a simple workflow that shows that problem (maybe by pinning data) and share it with us? So that we can debug and find out what the heck is going on here.

Here is a hint: the Merge (Append) node is not working the way I expect.
Either it’s a bug, or I don’t understand the intended operation.

Both the Merge input nodes are pinned and are supplying data:

  • Input #1 gives dbVars
  • Input #2 gives vars, hBody, and acts
    but Merge (Append) node does not pass anything from Input #2.

If I change the Merge node to “Choose Branch (Input #2)”, then all fields from Input #2 are in the Merge output:

And if I change the Merge node to “Combine (multiplex)” then it does what I expect, passing all data from both inputs to the output:

Perhaps I misunderstand how the Merge “Append” is supposed to work??

MAYBE RELATED? [BUG] Merge node doesn't wait for both inputs

Hey @Matt_Blais,

Append will append the items so you will get the items from Input 1 then the items from input 2 so if you have 2 items in each when the merge runs you will have 4 items that contain the same fields they did going in.

If you wanted to merge the fields together rather than the inputs you would need Combine > Merge by Fields or similar which will merge the actual items together so your 2 items on each input would remain 2 items but it would contain both datasets.

1 Like

Thanks - that was my misunderstanding.

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