Howdy ya'll - anybody know how I can prevent user ...
# general
s
Howdy ya'll - anybody know how I can prevent user from entering in duplicate custom records? Not sure what I should be using for the ID...
s
there is a "prevent duplicate records" option you can turn on & set criteria for
s
Oh shoot really??? Where is that at??
Because that pretty much sounds exactly what I need!
Is it for all custom records?
Crud, unless I'm mistaken - it's only for Customers, Vendors, Partners, Contacts.
Thinking I might need to script this... Basically before submit script that returns user error if a saved search
m
NetSuite enforces no duplicates for external id, so maybe you can have a script / workflow use that
s
I was thinking about that, but then wouldn't the script just fail to set the Ext ID?
Like it would just be blank
r
No it will prevent the record creation
s
Really... Hmm... Alrighty I'll try that - I imagine I have to do a beforeSubmit script, right?
s
sorry i had to step away for a minute
r
Yes, that is correct
s
if you try to upload a record with an external id that is already in the system you will get an error that states "This record already exists" & the record will not be created
b
im not sure if you can set the externalid in a before submit on the new record
external id isn't really supposed to be used in suitescript and behaves unusually
i believe you can load an existing record and set it, or do an inline edit
r
I have tried before in custom records and it is being set
s
Shucks yeah I'm having a lot of trouble getting this to work...
It just throws an error and saves anyway
b
you can try sharing what you have
but you probably want what @rustyshackles has
s
Wait I just realized. Is it because I wrapped up the function in a try catch?
r
what's the error? This is what I have in my script
Copy code
var recBraintree = record.create({
            type: 'customrecord_aw_braintree_integration'
        });

recBraintree.setValue({
            fieldId: 'externalid',
            value: objTran.stId
        });
b
thats not something you would use in a before submit
but that should work, its setting a value on a before submit's context.newRecord that should fail
r
Sorry right, it not a Before Submit, it was a Map Reduce
s
Hmm but if it's a map reduce, how does that prevent the user from creating the record, since the script is run after the record has already been created? Unless I'm missing something?
Also, SUPER SUPER SUPER appreciate ya'll's help
b
your first idea of a search is the most obvious choice
its not safe if you have multiple users trying to submit records at the same time
you have to implement a locking mechanism if that is a concern