Hi all. Anyone knows how to prevent beforesubmit e...
# suitescript
d
Hi all. Anyone knows how to prevent beforesubmit execution in UserEvent Script 2.0? I need validate some fields and stop the submit if anyone dosent pass.
e
Use a client script,
saveRecord
. (You can return false to prevent submission)
d
Its can't possible to use UserEvent?
e
Not to prevent submission of the record, no
❤️ 1
k
Make fields mandatory
d
@Kevin I have some business logic to not make this fields mandatory
k
Got it
👍 1
e
In
beforeSubmit
, you can
throw
to stop record submission
But the user will lose any work they did on that record, so it is advisable to get as much validation into the client-side
saveRecord
as possible.
However, not all data comes through the UI
d
tks @erictgrubaugh
e
Think of user events as database triggers that are used to enforce data integrity. First level validation should really be on the UI client side.
e
^ Yes, exactly. I walk through all the various triggers a single record goes through here:

https://www.youtube.com/watch?v=coLkgeuTFFM▾

, including (I believe) talking about the
throw
approach
e
@erictgrubaugh my perception is that most NS devs are using User Event Scripts for the majority of their business logic processing and validation.
e
Yep, I would agree with that, and I would say the vast majority of my logic is triggered by User Events as well.
Client Scripts don't apply to imports, integrations, nor scripts/workflows creating/updating records, so a Client Script only catches a portion of records.
Generally my approach is to put the true business logic into a custom module that accepts a normalized form of record data (i.e. an Object, not a
Record
instance). That way I can trigger the custom module from any of the various entry points I may need it.
👍 2