Skip to main content

Hi, I have a webhook coming from an external API.

Currently, some fields from that API are empty.

The webhook returns a string in this format:
Name: name1,name2

I added code to split this string into:
Name: name1
Name: name2

My code is designed to display all fields. However, the problem is that empty fields are not visible when I add them in my loop.

I want the fields with empty values to still be mapped during Salesforce record creation. But the issue is that I can't find those fields or values in the record or from the webhook.
 

Here's my code:

let fields = Object.keys(inputData);
let values = {};

// Handle lone comma strings or empty input as empty array
fields.forEach(field => {
  let raw = inputDatatfield] || '';
  let split = raw.split(',').map(item => item.trim());

  // Treat as ] if all items are blank
  if (split.every(item => item === '')) {
    values field] = e];
  } else {
    values field] = split;
  }
});

// Determine how many records to create
let recordCount = Math.max(...Object.values(values).map(arr => arr.length), 1);
let records = ];

// Build each record, showing every field even if it's empty
for (let i = 0; i < recordCount; i++) {
  let record = {};
  fields.forEach(field => {
    let val = valuesefield]=i];
    recordbfield] = typeof val === 'undefined' ? '' : val;
  });
  records.push(record);
}

return { records };

Hi ​@reinierdc 

For us to have true context, post these screenshots:

  • how your Zap steps are outlined
  • how your Zap steps are configured in EDIT mode with the field mappings visible
  • the DATA OUT returned from the Zap step you are trying to split

This is how my zap are.


I can't find "Solar" in the loop. I'm sure it's not there because both the input data and the output data in the code by zapier do not include "Solar".
So, does this mean there's a problem with my code, or is there another possible solution for this?

 

cc ​@Troy Tessalone 


@reinierdc 

Post screenshots showing these:

  • how your Zap steps are configured in EDIT mode with the field mappings visible
  • the DATA OUT returned from the Zap step you are trying to split
    • Step 1 (trigger)
    • Step 2 (Code)

 

 

 

 


@reinierdc 

Screenshots still do not show the DATA OUT form the Zap trigger step to allow us to see the structure of the returned data from the webhook data payload.


Hi ​@Troy Tessalone  Here is the sample data from that webhook first action. Some of the fields or data there might be empty. Example: Lead Size, Timeframe and it show just empty like other screenshot below

 


@reinierdc 

The data from the Zap trigger step webhook data payload returns an array of objects. (object means with properties)

Nesting: Lead > Response > Lead > 1

The 1 means the first array object.

 

So you should not need the Code step.

Instead, try mapping the data from the Zap step 1 to the Zap action: Looping - Create Loop from Line Items

Help links for Looping: https://zapier.com/apps/looping/integrations#help

 


So, no need for me to code step. instead loop directly from webhook?

CC: ​@Troy Tessalone 


I already tried it and it works for not using code step.

However, I want the field empty to map it in salesforce as well.

Example: Lead Response Lead EV Existing Solar Size is empty value from the webhook. Now, I added it on the loop values.



However, when I attempt to add that field during Salesforce Lead creation, it does not appear. How can I dynamically assign a value to it, regardless of whether the user provides an input?

 

CC: ​@Troy Tessalone 


@reinierdc 

Add a temp “X” value for the right side.

Then test the Zap step.

That should give you a variable to map.

Map the variable to the Salesforce step field.

Then go back to the Looping step and remove the “X”

 


So thats all? removed the temporary value and add the field again?


@reinierdc 
Yes.

When in doubt, test it out.

Turn the Zap ON.

Test live.

Check your Zap Runs history to see the DATA IN/OUT for each step: https://zapier.com/app/history/