Unique Alpha-Numeric Formula
Hello,
I want to create a trigger on create, that will assign a field named "Case Serial" a unique alpha-numeric data. I would prefer if the Case Serial was 12-digits long. For example:
L=Random letter A-Z
0=Random Number 0-9
L00LL00LLLLL
4 replies
-
Create an array of the letters A thru Z..
in a while loop.... use the random function to randomly pick on of the array items.. Not sure if Ninox has an undocumented randbetween function like Excel has.. If not. .You may need to get creative... concatenate the strings. (using +) ... then select against your source to ensure it does not exist..
I am sure there are some gaps in the above thinking.. but sounds like it would work.. .. If I get time.. I may hack an example in the console.
-
OK.. First hack is as follows.. does not address the alternating alpha / numeric pattern.. nor does it address uniqueness of key value ..
let alphaArray := ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
let keySize := 12;
let key := "";
for i in range(0, keySize) do
let r := round((random() * 100) / 3);
while r > 25 do
r := round((random() * 100) / 3);
end;
key := key + item(alphaArray, r);
end;
key; -
OK.. Hack 2 ... address the alternating pattern.. you can add a count select against the unique table source and put in an outer loop. ;) May not be the most elegant .. but it works and it was a quick hack.. :)
let alphaArray := ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
let keySize := 12;
let key := "";
let r:= 0;
for i in range(0, keySize) do
if (i = 1 or i = 2 or i = 5 or i = 6) then
r := round((random() * 100) / 3);
while r > 9 do
r := round((random() * 100) / 3);
end;
key := key + r;
else
r := round((random() * 100) / 3);
while r > 25 do
r := round((random() * 100) / 3);
end;
key := key + item(alphaArray, r);
end;
end;
key; -
See table "UniqueKey"
http://mconneen.infointegrators.net/ninox/NX-Language-Tutorial.ninox
Content aside
- 6 yrs agoLast active
- 4Replies
- 2602Views