Skip to main content

Expected behavior on Pre-Save Page JS Hook error

Comments

2 comments

  • Anirudh Sundaram Senior Integration Engineer
    Engaged
    Great Answer

    Hi Jim,

    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: []
    }
    }
    0
  • James K

    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.

    Thank you again!

    Jim

    0

Please sign in to leave a comment.