Hello guys (and girls), I hope one of you can help me out with the following problem: For our batch numbering i’ve created a new no. serie where i make use of the default numbering (automatically). This because the batch no. has to be unique. Example: A001, A002, A003… The problem is that i would like to use a random numbering where each number must be unique. Example: A001, A871, A342… Is this possible in Navision? Thank you for thoughts! Greetzz, Henry
Perhaps we can help if you can explain why you want the unique batch numbers? Django
Check out the C/AL commands RANDOM and RANDOMIZE. The Help for RANDOMIZE for V2.6 follows: Use this function to generate a set of random numbers, from which RANDOM will select a random number. RANDOMIZE([Seed]) Seed Date type: integer A number RANDOMIZE uses to create a unique set of numbers. If you use the same number as seed, you get the same set of numbers generated. If you omit this optional parameter, RANDOMIZE uses the current system time (total number of milliseconds since midnight).
Why that? random and randomize(without parameter is best) generate efectively random number. But your random number is for a primary key, so it must be unique … So when you have a number with random, you have to test if this number exist, if yes, you must chose another number and retest, … If you chose a range of value from 1 to 1000 to chose random, first key, it’s good, but when you have 800 record, your loop will be long time … I think it’s not a good choice to use random number to chose primary key. (scuse my english)
Actually, you could use the standard rec.insert function to get the unique key. If the randomly generated key is unique, the record can be inserted, if not you have to generate another key. I think you would have to use a REPEAT … UNTIL loop to do this.
Everybody thanks for your thoughts. I can use them very good. Actually i was looking for a solution where i use a no. serie and with some code in the table pick up a random number from this no. series. This should be done once for every number (because it has to be unique). If there is somebody how has some other thoughts about random numbering please let me know. For this moment i will use the solution mentioned above. So thanks again David, Geoffry, Dango and Tim. BTW Django, i want to use an unique batch number because of Re-Call (GMP regulations). Greetz, Henry
Re-Call??? GMP regulations???
The way I read the Help information, the RANDOMIZE and RANDOM functions should fit your requirements. Good luck.
Just to beat my curiosity into submission - what would be the difference between a sequential numbering system and a random numbering system. Couldn’t you argue that a sequential range of numbers could be generated randomly and/or that if you have a finite number range that eventually you’d use all of the numbers in that range and you’ve come back to a sequential set of numbers. [:p] Django
Again, everybody thanks for your replies. PeterD: When something happens with your products (for example: ingredients are bad or will lead to sickness) then you have to get your products out of the market (Re-Call). GMP = Good Manufacturing Practice. David: Random(ize) function is OK and part of the solution but to get a batch no. unique is another part of the solution which isn’t solved yet. You must do a search on your database (does batch no. exists yes or no?). This will lead to bad performance. Django: I agree that sequential numbering will lead to an unique number. However in production this can lead to misunderstanding (errors are made easier). If anybody has some ideas how to get an unique number without having bad performance please let me know. Greetings, Henry
Could the numbers always increment by a random amount? ie: A104 A109 A132 A154 etc.? If your numbers can always increment then you can make use of a No. Series and your code will be reasonably fast since you don’t have to test for conflicts. Django
Re Searching impacting perfomance: if the data item in question is keyed properly, you will lose very little performance