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 };