Hi,
I have an action that retreives multiple records from salesforce.
I have a cognito form with a dynamic table and I want to populate the entry with the record data.
I created a zapier code action with the following parameters and I am getting errors.
I am not sure if I am going about this the right way and would appreciate any assistance.
Code by zapier
Event: Run Javascript
Input data: Records, Records
Code
let records = inputData.Records; // Ensure 'Records' matches the actual field name from input
// Check if records is undefined or null
if (!records) {
throw new Error('Records input is undefined or null');
}
// Parse records if it's a string
if (typeof records === 'string') {
records = JSON.parse(records);
}
// Ensure records is an array
if (!Array.isArray(records)) {
throw new Error('Records input is not an array');
}
// Aggregate the data into the desired format
let aggregatedData = records.map(record => {
return {
Name: record.Name, // Adjust field names to match your specific needs
CreatedDate: record.CreatedDate,
LastModifiedDate: record.LastModifiedDate,
// Add more fields as necessary
};
});
// Return the aggregated data as a JSON string
return { aggregatedData: JSON.stringify(aggregatedData) };