I have a pre-save-page hook on the initial export step from SalesForce via SOQL query. The JS hook does several data transforming steps, one of which is to parse item descriptions so that NetSuite can utilize them properly. This script has functioned flawlessly for many months. An item description, however, happened to come through with a null value which caused an error.
My issue is with how Integrator IO handled the error. The error occurred on 1 record out of an array 8 exported. However, all 8 records were failed and the flow did not execute any subsequent steps for any of them. Although the other 7 were perfectly fine data-wise, they all errored with using the message of the failed record ("TypeError: Cannot read property 'replace' of null").
Question: is this expected behavior? If the pre-save page hook fails on one record, why does it then fail all of them? At the very least, it should not report false errors on the records that are perfectly fine (misleading and causes extra time to troubleshoot).
By design, the pre-save page hook runs on an entire page of records, so if one of the records causes an unhandled error then the entire page will fail. To prevent that from happening, you can wrap the per-record logic in a try-catch block. In the catch block, you can push a custom error message into the options.error array to indicate that an error was caused while processing the record. This error will be displayed on the export step. Finally, you can set that record object to null so that it is not processed in the subsequent step(s).
Thanks,
Anirudh
function preSavePage (options) { for(let i = 0 ; i < options.data.length ; i++) { try { let y = options.data[i].value.replace('x','y'); //logic that causes an error } catch(e) { options.errors.push({ "code": "custom_error", "message": "Error with record: " + options.data[i].id }); options.data[i] = null; } } return { data: options.data, errors: options.errors, abort: false, newErrorsAndRetryData: [] } }
Thank you for you reply. I was not aware we were able to add record-specific error messages to the log. The try/catch will be a good tool for isolating what records encounter problems in the JavaScript hooks.