Unofficial Content

Below are some alternatives for generating unique primary keys values.

1) Set the Autonumber attribute property (for numeric single keys) = True.

For more information read here.

2) Define the "numerator procedure" method (for numeric single keys, too).

Create a transaction that has the following structure:

Numerator
{
  NumeratorCode* - Char(6)
  NumeratorLastNumber - Numeric(10)
}

Then, suppose you have defined the following transactions:

Customer
{
   CustomerCode* - Numeric(10)
   CustomerName - Character(80)
}

Product
{
   ProductCode* - Numeric(10)
   ProductName - Character(200)
}

After that, create a procedure like this:

Autonumber Procedure

Rule:
Parm(&NumeratorCode, &NumeratorLastNumber);

Source:

For Each Numerator 
    where NumeratorCode = &NumeratorCode
    &NumeratorLastNumber += 1
    NumeratorLastNumber += 1
when none
    new
       NumeratorCode = &NumeratorCode
       NumeratorLastNumber = 1
       &NumeratorLastNumber = 1
    endnew
EndFor

Finally, in the Customer transaction rules section, you have to invoke the procedure as follows:

CustomerCode = Autonumber('CUS') on BeforeInsert;

Also, in the Product transaction rules section, you have to invoke the procedure as follows:

ProductCode = Autonumber('PRO') on BeforeInsert;

Get basic samples here

Two Level transaction 

In two-level transactions, the Serial rule is an option for second level numbering.

Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant