HOW TO: Use handlebars regexReplace expression to set a null field to an empty string

Q: If a particular field is null, I want to set the mapping to an empty string, "".

A: Use the following handlebar expression to set the mapping to an empty string if the field (note) is null. You can use this in conjunction with the Discard if empty checkbox to discard this mapping if note is null. Here, note is a field reference.

{{#if note}}{{{regexReplace note "" "(Field name: )" w}}}{{else}}{{/if}}


Here are a few tips:

  • Do not use any double quotes, curly braces, or parens to reference a field / variable, just type in the name
  • Use double quotes to reference a hard-coded string



What if you would like to map to an empty cell or true null, not a empty string with, ""? I run into issues where the field will not write to the source field as a empty string, "", if the source field's data type is anything other than string.

Hi, @felipestarling. I ran your question past some handlebars experts to see how that issue is usually resolved.

Of course, the data type and how it’s interpreted in a request depends on the endpoint app, but in our testing, one of these solutions usually wins out:

  • Replace the empty string ("") with "null" for the value, especially when an integer is expected
  • Try entering a space character (" ") for a string value