Generate number/dblookup on it

Hello,

I need to generate a random number and verify if that number exist in an other document. I need to generate a unique number

I will use this : @Round( ( 1 - 99 )*@Random + 99) to generate the number

I will use a view with one sorted column so I will be able to do a @DbLookup(“”:“NoCache”;“”:“”;“VUE_0003”; random number here )

I do not know exactly how to write the code, probably something like this:

rnd = @Round( ( 1 - 99 )*@Random + 99)

@while( @DbLookup(“”:“NoCache”;“”:“”;“VUE_0003”; rnd ) ; rnd = @Round( ( 1 - 99 )*@Random + 99) )

I need to generate a number until the dblookup find nothing, then I will assign the value to the field.

Thanks

Subject: generate number/dblookup on it

Does it need to be a number?

If not, just use @Unique to generate your unique key.

Subject: generate number/dblookup on it

in a button this works (tested and confirmed):

rnd := @Round(98 * @Random + 1);

@While(!@IsError(@DbLookup(“”:“NoCache”;“”:“”;“VUE_0003”; rnd;1));

rnd := @Round(98 * @Random + 1));

@SetField(“num”; rnd)

Checks column 1 (sorted) in the VUE_0003 view and if it finds the number it keeps going until it does not find a number then sets the num field to that number value.

Subject: generate number/dblookup on it

Does it have to be numeric? My suggestion would be to use @Unique to generate a unique alpha-numeric string…This way, there will be no need for a DbLookup to be performed…

HTH

Subject: RE: generate number/dblookup on it

I thought @unique worked only on string, like this: @Unique(“red”:“green”:“blue”:“red”) = red,green,blue. I still need to go through all the documents.

Subject: RE: generate number/dblookup on it

@Unique, when used in a computed field without any parameters, generates a unique value…

Subject: RE: generate number/dblookup on it

it is good to know…

thank you very much