Preventing an empty field being mapped

:bullseye: What is your goal?

I want to prevent an empty field (optional address line) being passed from a Cognito form entry to a Zoho contact

:thinking: What is the problem?

I have had assistance from Merlin, but I’m not sure how to put it into practice!

:test_tube: What have you tried so far?

This is the advice:

The removeEmpty function is a custom IML function that you need to use in the mapping area of your Zoho module, not as a separate function selector. Here’s how to implement it:
How to Use removeEmpty in Your Scenario

Instead of looking for removeEmpty as a standalone option, you need to wrap your data with the function directly in the field mapping:

Step 1: Add the removeEmpty Function

First, you need to define the removeEmpty function in your scenario. You can do this by using it in a mapping expression:

function removeEmpty(input) {
if (typeof input !== “object” || input === null) return undefined;
return Object.entries(input).reduce((acc, [key, value]) => {
if (Array.isArray(value)) {
acc[key] = value.map(item => removeEmpty(item));
return acc;
}
if (typeof value === “object” && value !== null && !(value instanceof Date)) {
if (Object.keys(value).length === 0) return acc;
acc[key] = removeEmpty(value);
return acc;
}
if (value === null) return acc;
acc[key] = value;
return acc;
}, {});
}

Step 2: Apply removeEmpty to Your Address Field

When mapping the address field in your Zoho module, instead of directly mapping the address object, wrap it with the function:

{{removeEmpty(addressObject)}}

Or if you’re mapping the entire body:

{{removeEmpty(parameters)}}

What removeEmpty Does

The function automatically:

Removes empty objects (like an empty address: {})
Removes null values
Processes nested objects and arrays recursively
Prevents validation errors from APIs that reject empty collections

This way, empty address fields from Cognito Forms will not be sent to Zoho, avoiding the “Field cannot be empty” validation errors.

Unfortunately, I cannot see how to add that function or then use it in the list of mappings

Yeah I don’t know what Merlin is, but shut it down and don’t use it again.

You can just map the address field in there, and if it’s empty, nothing will get sent anyways. If you are getting an error, please share a screenshot.

Hi,

Custom functions are available only on Enterprise plans.

But most likely you don’t need any function here- just map the output. If it’s empty… it will be empty.

There is one case where empty values really matter: a custom API request (e.g. via the HTTP module) to an API that treats empty values as data to be deleted. In that case, you have to omit the keys you don’t want to update.

Have a nice day,
Michal

Hi - thanks for the responses. Firstly - Merlin is the bot that Make offer to try to stop the likes of me bothering the likes of you, so I assumed it was the way to go.
The problem I have is that the field that may be empty is an address field, and when the address is used, say in an invoice, a blank line appears, and that’s what I’m wanting to avoid

Oh so you want to avoid the second one? I assume you have a new line after the first address so if the second address is empty, a blank new line will appear?

Yes, that’s right; if the field Address:Address line 2 (optional) contains merely a carriage return, I’d prefer the scenario to skip it so that that carriage return doesn’t result in a blank line being shown in the invoice address block

You can use an if() function to check if address two is empty. If it’s empty, return {{null}} and if it’s not empty, return a {{newline}} followed by address two.

Thank you - that’s most helpful