This article explains how to use the postSubmit hook to ignore error messages in a flow that syncs Shopify refunds data into NetSuite.
Note: For more general information about the postSubmit hook, see postSubmit hook.
Contents

In this example, when you import customers, there are some customers whose subsidiary value should not be updated, and those records cause a specific error. In such cases, you can use this strategy to check for that specific error message and ignore it so that those errors do not generate notifications.

Inspect error message
You can use Postman to call NetSuite to see the response error, but this example uses Slack to inspect the error response.
- Add a Slack page processor:

- Add the following response mapping for the Oracle NetSuite flow step and sets the flow to continue even if there is an error:


- On the Slack field mapping, send the error message to your slack application:

Here is the Slack output:

Here is the responseData reconstructed to facilitate the discussion of massaging error messages.
"responseData": [
{
"statusCode": 422,
"errors": [
{
"_userId": "5d93d813fe3c7b0ef52e58e8",
"resolved": false,
"code": "cant_modify_sub",
"message": "Failed to save record. You can't change the subsidiary of this entity because one or more transactions exist for this entity.",
"source": "netsuite",
"exportDataURI": null,
"traceKey": "2178928902215"
}
],
"ignored": false,
"id": "ExampleID",
"_json": {ExampleJSON},
"dataURI": "ExampledataURI"
}
]
Add script to process error message (postSubmit script)
The code below follows the code structure of the example provided above, but the condition to check for a specific message is highlighted:
function postSubmitNSCreateCustomerError(options) {
let responseData = processPostSubmitErrors(options, ignoreCreateCustomerErrorFn)
return options.responseData
}
function ignoreCreateCustomerErrorFn(options) {
let toReturn = {ignored: options.ignored, betterMessage: options.message}
//Check for specific error message inside "errors"
if (options.source === 'netsuite' &&
options.code === 'cant_modify_sub' &&
options.message.includes('Failed to save record because You cannot change the subsidiary of')) {
toReturn.ignored = true
toReturn.betterMessage = ''
}
return toReturn
}
function processPostSubmitErrors(postSubmitOptions, myProcessErrorFunction) {
postSubmitOptions.responseData.forEach(function(rd, i) {
if (rd.statusCode !== 422) return
let processedErrors = []
rd.errors.forEach(function(re) {
let errsHelper = []
let parsedMessage = re.message
try {
parsedMessage = JSON.parse(re.message)
} catch (ex) {}
// Modify the following for your needs.
if (typeof parsedMessage === 'object') {
if (Array.isArray(parsedMessage)) {
errsHelper = parsedMessage
} else if (Array.isArray(parsedMessage.errors)) {
errsHelper = parsedMessage.errors
} else {
errsHelper.push({code: re.code, message: re.message})
}
} else {
errsHelper.push({code: re.code, message: re.message})
}
errsHelper.forEach(function(e) {
let processedErrorMessage = myProcessErrorFunction({
code: e.code || re.code,
message: e.message || re.message,
source: re.source,
ignored: re.ignored,
preMapDataRecord: postSubmitOptions.preMapData[i]
})
processedErrors.push({
code: e.code || re.code,
message: processedErrorMessage.betterMessage || e.message || re.message,
source: re.source,
ignored: processedErrorMessage.ignored || re.ignored
})
})
})
rd.errors = processedErrors
let allErrorsIgnored = true
for (let j = 0; j < processedErrors.length; j++) {
if (!processedErrors[j].ignored) {
allErrorsIgnored = false
break;
}
}
if (allErrorsIgnored) {
rd.ignored = true
rd.errors = []
if (!rd._json) rd._json = {}
rd._json.ignoredErrors = processedErrors
}
})
return postSubmitOptions.responseData
}
Here is the preview of function output when you run the script inside the script editor:

Testing the code
The following animation demonstrates how to test the code:

Comments
0 comments
Please sign in to leave a comment.