I am running into one more issue getting the flow from my earlier post working:
In this flow I am sending a batch of records to an HTTP POST, and I am inserting the field mapping results into the HTTP body using the expression below (which works great!):
The issue is that I needed to conditionally add an array of objects into each record (with a variable number of elements). I couldn’t see any way to do this in normal field mapping, so I added a postMap function to do this. The postMap function seems to work great in preview, but when I run it and check the debug log, it doesn’t seem to get called between the mapping and the expression evaluation to build the HTTP body (see expression above).
Do you have any mappings set? The postMap script will only run if there are mappings.
Are you sure you're returning the data correctly in the postMap script? I typically see issues where users don't return the data correctly according to the function stub, which then leads to issues.
/*
* postMapFunction stub:
*
* The name of the function can be changed to anything you like.
*
* The function will be passed one argument 'options' that has the following fields:
* 'preMapData' - an array of records representing the page of data before it was mapped. A record can be an object {} or array [] depending on the data source.
* 'postMapData' - an array of records representing the page of data after it was mapped. A record can be an object {} or array [] depending on the data source.
* '_importId' - the _importId currently running.
* '_connectionId' - the _connectionId currently running.
* '_flowId' - the _flowId currently running.
* '_integrationId' - the _integrationId currently running.
* '_apiId' - the _apiId currently running.
* '_parentIntegrationId' - the parent of the _integrationId currently running.
* 'settings' - all custom settings in scope for the import currently running.
* 'sandbox' - boolean value indicating whether the script is invoked for sandbox.
* 'testMode' - boolean flag indicating test mode and previews.
* 'job' - the job currently running.
*
* The function needs to return an array, and the length MUST match the options.data array length.
* Each element in the array represents the actions that should be taken on the record at that index.
* Each element in the array should have the following structure:
* 'data' - the modified/unmodified record that should be passed along for processing.
* 'errors' - used to report one or more errors for the specific record. Each error must have the following fields: {code: '', message: '', source: '' }
* Returning an empty object {} for a specific record will indicate that the record should be ignored.
* Returning both 'data' and 'errors' for a specific record will indicate that the record should be processed but errors should also be logged.
* Throwing an exception will fail the entire page of records.
*/
function postMap(options) {
return options.postMapData.map((d) => {
return {
data: d
}
})
}
I checked in my own flow and see the postMap script being executed. I can see this by putting some console.logs and viewing the execution logs of the script.
I know the postMap function is called after the field mapping (from the mapping dialog) is processed, but is it called before or after the HTTP request body is built. You can see the expression to format the body below.