Is it possible to prevent a record to be imported ...
# suitescript
b
Is it possible to prevent a record to be imported via CSV by using an UE script? So the idea is that I also want to make sure that it's visible for the user how many records failed during the CSV import. At the job status one should easily should see how many records failed during the import.
c
Just throw an exception in the beforeSubmit
👍 1
n
A User Event on the specific record can check the context is csv import and you can throw an error on the before submit. The error you throw is the one that the user should see in the list you mention. <-- to be clear I mean the file you downloaded with the errors in it.
👍 1
b
Hi CD, yes I tried it and it didn't worked. Now somehow it does :S
Sometimes NS drives me crazy
message has been deleted
@NElliott thx man! Yes I used that one too, now it seems to work
c
You have to make sure you have the CSV context turned on in the deployment, plus "Execute Suitescript, workflows etc" is turned on in the advanced options when you do the CSV import
👍 1
n
^^ that's also a good point
b
Checked that one too and those were also enabled
Thanks guys for your fast replies.
👍 1
So what am I missing here, when I throw the error by creating an error object it works and it doesn't add the record. However when I enclose it within a try catch it won't throw the error and the record gets imported.
Copy code
try {
  
  const myCustomError = error.create({
    name: 'WRONG_PARAMETER_TYPE',
    message: 'Wrong parameter type selected.',
    notifyOff: false
  });

  throw myCustomError;
  
} catch (e) {
  log.debug('Try catch error', e.message);
}
c
Don't catch it
If you're not re-throwing in the catch you're effectively saying "I have caught this, and have dealt with it, so you can continue happily"
👍 1
b
ah okay