Developer forum

Forum » Templates » Generate random unique identifier (max 5 chars)

Generate random unique identifier (max 5 chars)

Adrian Ursu
Reply

Hey guys, 

Is there a way to generate a random unique identifier of a max of 5 chars (maybe 6), similar to a voucher code, by using some built in DW functionality? Strings and ints or just strings or just ints it really doesn't matter

Thanks!


Replies

 
Nicolai Høeg Pedersen
Reply

Here is an example:

http://stackoverflow.com/questions/1344221/how-can-i-generate-random-alphanumeric-strings-in-c

If you need to make 100% sure it is unique, you would have to store the generated codes and check it has not been created before.

BR Nicolai

 
Adrian Ursu
Reply

Hi Nicolai,

Thanks for the answer. Can't we just access the voucher code logic?

Is that accessible via the API?

We need to add a unique registration ID for every submitted form (for a contest) and we are using the Forms for Editor module.

Thanks,

Adrian

 
Nicolai Høeg Pedersen
Reply

You can call eCommerce.Orders.SalesDiscounts.Vouchers.Voucher.GenerateVoucher(listid, numberOfCharacters) where list ID is the ID of the Voucher code list to add the voucher to.

 
Adrian Ursu
Reply

Thanks a lot.

 

You must be logged in to post in the forum