Is it possible to prevent a record from submitting...
# suitescript
a
Is it possible to prevent a record from submitting and then display a custom error in a beforeSubmit user event script?
e
you'll need a client script for that
a
Trying to get an error for missing sublist fields (conditional which is why its in the script). I have a client script set up that works great, but client scripts wont work for csv uploads or integrations. Any ideas?
d
for CSV, throwing an error in a UE beforeSubmit entrypoint with result in the CSV line failing. Not sure for your integrations
a
How do I throw an error in the UE beforeSubmit?
d
use the
N/error
module to create your error and
throw
it. See the 2nd example on the N/error module help center page
a
So I did that, here's my current code, this error only shows up in the script log though. I would like for it to display when the user tries to save the record. It feels like I am missing something very small and it's driving me crazy
d
So for your client script (in the saveRecord entrypoint) you'll want to
alert('missing required sublist fields')
(or similar) _*and return false*_
actually, just throwing the error in the CS should have worked
a
The client script is working just fine, I am using the validateLine entry point with an alert and return false.
Any idea how to do that in a userEventScript though?
'that' meaning throw an error and prevent the record save. I thought I could prompt one of NS error pages with the message and a go back button. But I haven't been able to make that happen
Like this one
d
read this SO answer and this one. you used to be able to override the toString function, or use css to hide the native error JSON object. But it seems like both of those have been patched/have broken. Simply using this in the UE beforeSubmit
Copy code
throw 'Missing Required Sublist Fields<br> alert string here';
resulted in the user seeing this, which I think is satisfactory
it also resulted in the CSV import line failing, see below error NOTE, if the user imports the CSV with suitescripts and workflows turned off, they will circumvent the validation. Consider other means of making sure CSV imports are valid
a
Interesting, I'll have to play around with it some more today. For some reason whenever I throw an error in that way it only appears in the script log and still allows the record to be saved. I almost wonder if there's a setting I don't know about. Thanks so much for investigating this and giving such good info!