Anyone know of a solution to prevent duplicate Inv...
# suitescript
e
Anyone know of a solution to prevent duplicate Invoice Numbers (or any transaction type really) when creating them in mass via a Map/Reduce script? More context in thread
👀 1
✅ 1
We use a M/R script to generate multiple Invoices. But the issue (I'm assuming) is because we generate them during the Reduce stage we're using our concurrency and so essentially, multiple Invoices are being created at the same time, and I think NetSuite is determining the "next invoice number" at the same time, so when we actually save them, multiple invoices are given the same invoice number (INV100) even though they have different Internal Ids and are different records
c
@ericbirdsall Do you mean Transaction or Document Numbers? Do you "Allow Override"? Can you set the transactions to Generate TranID on Save?
e
tranid is the field in question here The transactions are set to Generate TranId on Save, but I think the issue is that NetSuite determines the TranId early on in the process Example: I create an Invoice and save it. It's TranId is INV0001 I start a new Invoice in the UI The TranId field is filled in with INV0002 I DONT SAVE THIS INVOICE YET I start ANOTHER new Invoice in the UI The TranId field is filled in with INV0002 (again, since INV0001 is the last SAVED invoice) I save both Invoices. Both invoices have a TranId of INV0002 I believe that is what's more or less happening in the M/R script as well. When I do record.create, NetSuite is looking for the last SAVED invoice number and incrementing it by one But since there are 5 threads each called record.create at more-or-less the same time, each of them is having their TranId set to INV0002
c
Hmm with "Generate TranId on Save," it shouldn't be showing a TranID in the UI, as it should be waiting to generate it until the moment it's saving it to the database.
e
Interesting, maybe I can just set that field to True in my record.create() I'll give it a try. Thank you!
c
Sure, let us know how it works out!
e
Got the expected result when I tested in the console! Will update my code in the M/R and keep you posted
✨ 1
Success! Thank you @Clay Roper