JavaScript: Combining conditional results into single string output for Zapier integration

I’m working on a JavaScript function that checks spreadsheet values and displays messages when certain conditions are met. Right now my code works but creates separate array items for each result.

The problem is that when I use these in an email with Zapier, they get separated by extra line breaks which looks messy. What I want is to combine all the results into one string. Here’s my current approach:

var status1 = inputData.STATUS1;
var message1 = (status1 === "FALSE") ? "Missing required training manual" : "";

var status2 = inputData.STATUS2;
var message2 = (status2 === "FALSE") ? "Need updated safety equipment" : "";

var status3 = inputData.STATUS3;
var message3 = (status3 === "FALSE") ? "Certificate renewal pending" : "";

return {message1, message2, message3};

This creates multiple line items in Zapier. Instead, I want to return one string that combines all non-empty messages with line breaks between them. How can I modify this code to concatenate the results into a single output?

Had this exact problem building Zapier automations for our HR team. Multiple outputs were making our notification emails look terrible. Here’s what fixed it for me - create a results array upfront and push messages as you check each condition:

var results = [];

if (inputData.STATUS1 === "FALSE") {
    results.push("Missing required training manual");
}
if (inputData.STATUS2 === "FALSE") {
    results.push("Need updated safety equipment");
}
if (inputData.STATUS3 === "FALSE") {
    results.push("Certificate renewal pending");
}

return {combinedOutput: results.join("\n")};

This scales way better when you add more conditions and handles empty cases cleanly - no conditions triggered means empty string instead of undefined. I’ve used this for months with zero problems.

Just collect all your messages and combine them before returning. Don’t return separate properties - build one concatenated string instead:

var combinedMessage = "";
if (status1 === "FALSE") combinedMessage += "Missing required training manual\n";
if (status2 === "FALSE") combinedMessage += "Need updated safety equipment\n";
if (status3 === "FALSE") combinedMessage += "Certificate renewal pending\n";

return {finalMessage: combinedMessage.trim()};

The trim() cuts off any trailing newline. This gives you better control over formatting and it’s way easier to debug than array methods when you’re working with conditional messages.

push your messages into an array, filter out the empty ones, then join with \n. try [message1, message2, message3].filter(msg => msg).join('\n') - way cleaner than returning separate properties.