https://netsuiteprofessionals.com logo
#suitescript
Title
# suitescript
s

Sean Hayes

04/23/2022, 9:34 PM
CSV Import Validation via UE on beforeSubmit() Throwing an Error object with
notifyOff
as
true
correctly prevents the import without notifying via email as an Unhandled Error, but the CSV File contains the entire stringified ERROR Object. This is ugly and initially confusing for users. I can throw the message without creating the error Object, but this will trigger the email notification, and we can’t have that, since these are validation errors, which users will definitely encounter, and we don’t want to blow up our inboxes with false-positives… Has anyone accomplished this differently with a better result?
Thanks for the assist @battk!
Created a function to override toString() for CSV User Errors.. works great!
Copy code
throw createCSVUserError({
name: 'CSV_VALIDATION_ERROR',
message: 'You can only use XXX Account for this transaction!',
notifyOff: true
});

/**
 * Create an Error Object which prints only the Error Message when toString() is called.
 * @param {Object} errorOptions
 * @return {Object} error
 */
function createCSVUserError(errorOptions) {
  const csvUserError = error.create(errorOptions);
  if (errorOptions.notifyOff) {
    // log the original error
    log.error({title: 'Returning CSV User Error', details: csvUserError});
  }
  // print only the error message to the csv error line.
  csvUserError.toString = () => {
    return csvUserError.message;
  };
  return csvUserError;
}