Anyone know how to generate a GUID in SuiteScript?...
# suitescript
a
Anyone know how to generate a GUID in SuiteScript? There is info on GUID for Secretkey in the Crypto module, but is not what I'm looing for
b
pick your favorite uuid package from npm
a
They are node modules which do not seem to work in Netsuite due to dependancies
b
some are node only, some support browsers
browser specific package repositories are nowhere near as popular as npm
a
I found this one, which is a single script. Problem is the UUIDs generate are not unique https://github.com/rse/pure-uuid
b
choose v4 to get random uuids
a
They are random for a while, but eventually it generates duplicates
Wondering if anyone has a library they were able to import into NS and have it generate truly random uuids
b
as in you saw it generate a duplicate?
a
Yes, several duplicates with 60k generated uuids
While the script does not generate duplicates when used in unit tests, when it sits in Netsuite it eventually generates duplicates
b
what did the script look like
a
Not exactly sure what you mean. I called this uuid script via a Sales Order User Event script to assign a uuid value for each Sales Order. I created a function to get the uuid which is ...
Copy code
const getNewId = () => {
            const newUuid = new uuid(4);
            return newUuid.format();
        }
This returns a uuid, but eventually returns a non-unique value
I have also tried the 8.3.2 version (last version with a UMD build) of this one https://www.npmjs.com/package/uuid, but the problem is
crypto.getRandomValues
is not supported and the polyfill doesn't work either
Seems all uuid generators require
crypto.getRandomValues
b
you will probably have to polyfill it yourself
its not great, but allows you to polyfill a fake random generator