How to capture retry data with preSavePage hook

Hi,

I have created preSavePage script to validate and show an error when one of the field is null. This script runs after data is extracted from snowflake query. the error doesn't show retry data.

Script:

function preSavePage(options) {
  for (var i = 0; i < options.data.length; i++) {
      try {
          if (!options.data[i].SERVICENOW_SYS_ID.length >= 1) {
              throw new Error('CustomerSYSID not found');
          }
      } catch (e) {
          options.errors.push({
              "code": "Customer SYS ID not found",
              "message": "Customer ID Error with record: " + options.data[i].CONTRACT_LINE_ID,
              "source": + options.data[i].CONTRACT_LINE_ID
          });
      }
    }

  return {
      data: options.data,
      errors: options.errors,
      abort: false,
      newErrorsAndRetryData: [options.data]
  }
}
0

Comments

2 comments
Date Votes
  • Krunal Patel you need to put your error and record data within the newErrorsAndRetryData field. Make sure to follow the instructions of the preSavePage script stub. See modified script and sample error output:

    /*
    * preSavePageFunction stub:
    *
    * The name of the function can be changed to anything you like.
    *
    * The function will be passed one 'options' argument that has the following fields:
    *   'data' - an array of records representing one page of data. A record can be an object {} or array [] depending on the data source.
    *   'files' - file exports only. files[i] contains source file metadata for data[i]. i.e. files[i].fileMeta.fileName.
    *   'errors' - an array of errors where each error has the structure {code: '', message: '', source: '', retryDataKey: ''}.
    *   'retryData' - a dictionary object containing the retry data for all errors: {retryDataKey: { data: <record>, stage: '', traceKey: ''}}.
    *   '_exportId' - the _exportId currently running.
    *   '_connectionId' - the _connectionId currently running.
    *   '_flowId' - the _flowId currently running.
    *   '_integrationId' - the _integrationId currently running.
    *   'pageIndex' - 0 based. context is the batch export currently running.
    *   'lastExportDateTime' - delta exports only.
    *   'currentExportDateTime' - delta exports only.
    *   'settings' - all custom settings in scope for the export currently running.
    *
    * The function needs to return an object that has the following fields:
    *   'data' - your modified data.
    *   'errors' - your modified errors.
    *   'abort' - instruct the batch export currently running to stop generating new pages of data.
    *   'newErrorsAndRetryData' - return brand new errors linked to retry data: [{retryData: <record>, errors: [<error>]}].
    * Throwing an exception will signal a fatal error and stop the flow.
    */
    function preSavePage(options) {
      
      let newErrorsAndRetryData = [];
      let errors = [];
      
      for (var i = 0; i < options.data.length; i++) {
        try {
          if (!options.data[i].SERVICENOW_SYS_ID.length >= 1) {
            throw new Error('CustomerSYSID not found');
          }
        } catch (e) {
          newErrorsAndRetryData.push({
            retryData: options.data[i], 
            errors: [{
              "code": "Customer SYS ID not found",
              "message": "Customer ID Error with record: " + options.data[i].CONTRACT_LINE_ID,
              "source": + options.data[i].CONTRACT_LINE_ID
            }]
          });
        }
      }

      return {
        data: options.data,
        errors: options.errors,
        abort: false,
        newErrorsAndRetryData: newErrorsAndRetryData
      }
    }

    1
  • Thank you so much Tyler Lamparter. I wasn't aware we needed push retry data to newErrorsAndRetryData.

    0

Please sign in to leave a comment.

 

Didn't find what you were looking for?

New post