How to replace empty fields with value of 1st row?

Describe the problem/error/question

How to I replace empty fields with whatever the value is in the first row? for example I have a table that looks like this:

Column 1 Column 2
Folder1 abcdefgh
Folder2 [null]
Folder3 [null]
Folder4 [null]
Folder5 [null]

I want the final output to look like this:

Column 1 Column 2
Folder1 abcdefgh
Folder2 abcdefgh
Folder3 abcdefgh
Folder4 abcdefgh
Folder5 abcdefgh

How can I do this?

What is the error message (if any)?

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • **n8n version:1.89.2
  • **Database (default: SQLite):default
  • **n8n EXECUTIONS_PROCESS setting (default: own, main):default
  • **Running n8n via (Docker, npm, n8n cloud, desktop app):npm
  • **Operating system:Windows Server 2022

Wasn’t sure which part of the workflow you were trying to do the fill-in-nulls thing, but here’s one way.

1 Like

I’m trying to do the fill-in with the Edit Fields node. I tried your method but it doesn’t work. It doesn’t work with item 2 and the rest of the items.

Here’s json if you want some data to test with

[
  {
    "dirs": "Beware the Villainess! (Digital) (1r0n)\r",
    "token": "b3usdmovi16a4ugvr5vf7pn2pb"
  },
  {
    "dirs": "Itaewon Class (Digital) (LuCaZ)\r"
  },
  {
    "dirs": "Overgeared (Digital) (LuCaZ)\r"
  },
  {
    "dirs": "Sword Art Online Re-Aincrad (Digital) (LuCaZ)"
  }
]

Your original question just said the field could be set to null. It didn’t mention the field could be missing. Anyway, that just requires another condition in the expression to check for undefined.

There is a somewhat lengthy discussion of the subtleties of checking for null, undefined, etc. here. If you still find that the expression isn’t quite right you can find some other ways to try in that thread. For instance, $json.token === undefined || $json.token === null COULD possibly be rewritten as $json.token == null (i.e. == instead of ===) or typeof($json.token) === 'undefined' || $json.token === null (i.e. explicit use of typeof, compared to string result). In any case, it would probably serve you to review the Javascript docs on operators.

3 Likes

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