How to create list of unique 3 character alphabet code. If i pass "AAA" and 2, it should return "AAB", "AAC". 2 unique codes after "AAA"
Discussion posts and replies are publicly visible
Random != Unique.
Very curious as to why you would need to do this but here is some code to generate a string variable length with random characters. Not unique though. You should look into UUIDs if you want to achieve this.
a!localVariables( local!character: "A", local!numberOfCharactersToAppend: 2, local!allCharacters: "ABCDEFGHIJKLMNOPQRSTUVWXYZ", local!charactersToAppend: a!forEach( items: enumerate(local!numberOfCharactersToAppend), expression: a!localVariables( local!randomIndex: rounddown((rand() * 26 + 1), 0), mid( local!allCharacters, local!randomIndex, 1 ) ) ), concat( local!character, joinarray(local!charactersToAppend, "") ) )
Thanks all for the response. venkat Avuluri If i pass "AAZ" and 2. its returning "AA[" and "AA\" where it should be "ABA" and "ABB"
Yup it's gonna give you that .I just pasted sample code how it needs be done
Mathieu Drouin said:Very curious as to why you would need to do this
Same here ,Can I know why you need this in the first place . We can suggest alternatives
When i add new records to the editable grid, it saves in database with generated unique code in a column. If i create 3 new rows, it needs 3 new codes to be generated to assign it to each row. There may situations where end user can delete already added row and at that time we need to recreate codes and assign to each row accordingly.
Are you sure this is a good way to solve the problem of primary key values?