The preSavePage hook is invoked on a page of records before the page is sent to subsequent steps in your flow. This hook can be used to add, update or delete records. This hook is a great place to execute logic on batches of records at the same time. For example:
- Filter or group records in batches
- Apply calculations in batches
- Perform complex data transformations in batches
- Validate data and return errors for records
Example: This preSavePage hook function replaces a potentially large sub-object with an error message if its size exceeds 500,000 characters (approximately 1 MB) in each data record.
function swapHugeSubObjectWithInlineErrorMsg (options) {
options.data.forEach(function(d) {
let size = JSON.stringify(d.potentiallyBigSubObject).length
if (size > 500000) {
d.potentiallyBigSubObject = {
errorMessage: "potentiallyBigSubObject 1MB"
}
}
})
return {
data: options.data,
errors: options.errors,
abort: false
}
}