Checking for value in Webhook Body with hasOwnProperty

I am having an odd issue after updating to 0.222.1 last night. I get a JSON payload from the webhook that sometimes will have a key called “remove” with the value set to “yes”. The value is always yes if the remove key is in the JSON.

I then set a variable in my code node that checks to see if that property exists in the Webhook payload, like this:

let remove = $node["Webhook"].json["body"]["0"].hasOwnProperty("remove");

I then use a switch to set a variable named “state”, like this:

    case (callerCallInfo != "active" && calleeCallInfo != "active" && remove == true):
        state = "ended";
        duration = 0;
        break;

My problem is that no matter if the “remove” key is in the payload or not, my remove variable always returns as true. I noticed this is happening on other variables using hasOwnProperty. This had previously been working so it could be something I missed in the changelog

EDIT
I adjusted my switch statement to include the following but it still returns true

default:
      remove = false;

EDIT 2
I’m able to get the correct boolean value if I use a Set node directly after the Webhook node like this:
RemoveBoolean

2 Likes

Same here !
.hasOwnProperty() doesn’t seems to work anymore in Code node…

As workaround you can still use !== undefined.

2 Likes

Did not know about that for undefined, thanks @JimwC!

same here.
all code with .hasOwnProperty(‘property’) failed since last update

@Jon @MutedJam have either of you heard of anyone else having this issue?

1 Like

Hi
I have exactly the same bug.
n8n selfhosted, version 0.222.2
All code block with .hasOwnProperty failed.

I must of missed this post, Before the updates what versions were being used?

before the update : 0.220.0

Worked correctly for me, until v0.219.1 (BUG: Faulty Javascript being implemented in the Code node after update to v0.222.3 - #4 by shrey-42)

Perfect thanks, I will start digging through releases between 220 and 222 and see if we can find what changed.

2 Likes

Have created N8N-6333 as our internal ticket for this one.

1 Like

New version [email protected] got released which includes the GitHub PR 6124.

1 Like

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