I need help with a JavaScript function that checks multiple conditions and combines the results into one string instead of separate array items.
Right now my code works but it creates multiple line items in Zapier. Each item becomes a separate entry which adds extra line breaks in my email output. I want to merge all the conditional results into a single string so Zapier treats it as one line item.
Here’s what I’m working with:
var STATUS_A = inputData.STATUS_A;
var product1 = (STATUS_A === "MISSING") ? "Training CPR Dummy" : "";
var STATUS_B = inputData.STATUS_B;
var product2 = (STATUS_B === "MISSING") ? "Emergency Response Kit" : "";
var STATUS_C = inputData.STATUS_C;
var product3 = (STATUS_C === "MISSING") ? "First Aid Supplies" : "";
result = {product1, product2, product3};
The issue is that when I use this in an email, I get unwanted spacing between items. I want to create a single concatenated string that includes only the items where the status equals “MISSING”, separated by line breaks, so the final email shows a clean list without extra spacing.
I’ve hit this same Zapier formatting issue before. The fix is simple - don’t return an object with separate properties. Build one string by filtering out empty values and joining them. Try this: javascript var STATUS_A = inputData.STATUS_A; var product1 = (STATUS_A === "MISSING") ? "Training CPR Dummy" : ""; var STATUS_B = inputData.STATUS_B; var product2 = (STATUS_B === "MISSING") ? "Emergency Response Kit" : ""; var STATUS_C = inputData.STATUS_C; var product3 = (STATUS_C === "MISSING") ? "First Aid Supplies" : ""; var products = [product1, product2, product3].filter(item => item !== ""); result = {output: products.join("\n")}; The filter removes empty strings, join combines them with line breaks. Zapier treats this as one item, so no more spacing issues in your emails. I use this pattern all the time - works great.
yea, that’s spot on! just skip empty strings by pushing results into an array directly, then join them at the end. it’ll keep things tidy without needing to filter out blanks later.
I hit this exact problem building automated reports in Zapier. The cleanest fix? Build the string conditionally without creating empty variables at all. Here’s what worked:
var result_string = "";
if (inputData.STATUS_A === "MISSING") {
result_string += "Training CPR Dummy\n";
}
if (inputData.STATUS_B === "MISSING") {
result_string += "Emergency Response Kit\n";
}
if (inputData.STATUS_C === "MISSING") {
result_string += "First Aid Supplies\n";
}
result = {output: result_string.trim()};
The trim() removes any trailing line break. This skips arrays entirely and builds your string incrementally only when conditions are met. I’ve used this across dozens of Zapier workflows and it handles edge cases way better than filtering empty strings after.