Do any have any good suggest some good library wh...
# suitescript
s
Do any have any good suggest some good library which creates an alphanumeric key which will not repeat again?
d
@samyt can you explain your use case a bit more?
I am guessing you want to make some unique key field
s
@David Durst Yes you are correct.
d
ok do you have a candidate key(s) in your data set?
meaning a set of fields when grouped together would guarantee to be unique?
s
Unfortunately, No.
d
what about if you added a time stamp to it?
s
I was tried using UTC timestamp. But it kinda long
d
Ah so you have a limit on your key length
this is going to be difficult because I was going to suggest you use a HASH library like MD5
s
If I limit it may repeat in future?
d
but those keys are much longer than a timestamp
are you trying to prevent a data collision?
meaning use this key to prevent duplication of data?
s
It just for identifying the records based on key
d
The only thing that comes to mind to solve this is a hash
trying googling for javascript MD5 hash library
s
How long will the key be?
d
128bits
s
ok
d
32 characters
s
OK Thanks
m
What you are looking for is called a "uuid". There are libraries, but this answer has a pretty simple implementation that is probably good enough for many use cases. https://stackoverflow.com/a/2117523
s
Thanks @michoel
c
If you're doing this server side in NetSuite you'll need a library that doesn't depend on the
crypto
api built into the browser. I had to do this a while back and ended up using https://www.npmjs.com/package/crypto-js. If you're doing it client side then @michoel’s suggestion is probably easier.