Set "NA" if field is empty

Hi folks, I receive data from a node with empty fields in several columns. To work properly further with the data in the workflow the fields should not be empty but set to NA or something like this… Is it possible to set all empty fields to a specific value in more than one column efficiantly in a single step? With IF and Set node it becomes a mass to split the data column wise and remerge it afterwords…

If you say “empty” what do you mean? Do they actually exist and are set to an empty string or do they not exist at all? So if you look in the JSON view do those fields get displayed there?

Hi @jan, both. some exist and they are empty strings "email2": "", and some do not exist in JSON view. Is it possible to create if they do not exist and then fill all empty strings with a defined value in some columns?

You can create a Function Node with the following code:

const requiredKeys = [
  'a',
  'b',
  'c',
];

items.forEach(item => {
  requiredKeys.forEach(key => {
    if ([undefined, ''].includes(item.json[key])) {
      item.json[key] = 'NA';
    }
  });
});

return items;

You just have to change the requiredKeys accordingly.

Here an example workflow:

1 Like

Sorry, was busy the whole day and had no time to check it sooner. Ach @jan, what shall I say… couldn’t be better. Thank you so much for your help. This is exactly what I need! :100: :ok_hand:

Great to hear. Have fun!