ERROR: Cannot read properties of undefined (reading 'startsWith') need your help to find the answer

Hello guys,

I have a list of departments and a postal code that I have set up with the SET node

I would like to keep only the departments that start with the same number

For that I use IF, the only solution would be to use Starts With but I have the following error:

I thought the error came from it being a number, so I used the .toString expression:

{{$node[“LISTE”].json[“CodePostal”].toString()}}

But nothing changes

Second option, keep only the first 2 digits of my postal code to look for an equality then but I didn’t find how to do it…

Here is an image of my workflow, to summarize when a new request arrives by mail, we get its postal code to compare it with our database and keep only the departments that correspond and then send an email :

Thank you for your time / help !

Hey @Clement,
welcome to the community :tada:

Looking at your example data I think your problem is that Code Postal is not set everytime. To bypass this problem you could use this expression.

image

This will do two things for you

  • Have an empty string “” if Code postal is empty
  • Convert the number to a string

Here is an example workflow to illustrate

1 Like

Thanks a lot for this solution !

There is indeed no more error but as you can see below, it does not work

I have one postal code, but I don’t think it tests all the departments on it :

I used the expression {{ $json[“Postcode”] + “” }} and {{ $json[“Department”] + “” }}

Configuring with SET in the front node to retrieve the zip code and departments may not be the best solution?
Or is it a bad use of IF ?

Thanks for your time !

Hey Clement,
if I understand correctly you are tryning to match CodePostal (Value 1) startsWith Departement (Value 2), right? In that case everything would go to false because e.g 69126 does not start with 34 and empty (CodePostal) does not start with 47, etc.

Are you trying to match a list of departements with each postal code? In that case the IF node I am seeing wouldn’t work because it will compare the first Departement with the first Code Postal, then the second Department with second CodePostal etc.

I created a sample workflow using two seperate lists for Departement and Code Postal and using the Merge node to multiplex all combinations of both together. After that your if node would work.

Here is my example workflow.

1 Like

Thank you @marcus for your answer,

I understand better why it doesn’t work, I had misunderstood the use of IF

It’s true that I was not clear on my workflow.

To explain better, when a person makes a request for a move via a form, I get his zip code in my Mysql database

Then I have another database on airtable with a large number of movers, and my goal is to find the number of movers that match the zip code through their departments

So I never have several zip codes to test but only one

Does your solution still work for this case?

Yes my solution would still work. In that case one zip code would be merged with all your movers so that you can compare the zip code to their departements using the if node.

You could also try to play around with the Airtable node list operation and the Filter by Formula parameter.

image

Thank you so much for your advice, everything works great now!

How can I close the topic?

Great to hear that it’s working now. I marked my merge node post as solution to close the topic. It’s alway good to pick a solution if possible or to like answers you were getting. A final message to make clear that everything works now is also alway great and you did so already :+1: