ConnectIT 365

Primary keys

Insert new records using OnInsert trigger
In many cases the value of a primary key field can be set automatically by the code on the insert trigger of the record.
For example, when inserting a Sales Header without a value for the No. field, when Run Trigger on Key fields is set to True, the next available order no. will be entered automatically.
Because of the Key Links, this value will be used on the child lines (Sales Lines) as well.

Function GETNEXTLINENO
In case the OnInsert trigger cannot be used to create a full PK, the function GETNEXTLINENO can be used on a constant lines. This function can be used for both line and entry nos, depending on the chosen increment.

Example Sales Header + Lines

  1. Make sure to

Run Trigger on Keys to set the (Document) No. field value.

  1. Make sure the “Document Type” field is filled using constants, for example

1.

  1. Add a Constant Line for Sales Line – Field No. = 4 (Line No. field) and add a function with Code

GETNEXTLINENO, for the Field No (of Line No. / Entry No.) parameter enter 4, for Increment enter 10000.
Now when processing import data, the system will create a Sales Header with the next available number from the no. series used for Sales Headers of the selected Document Type.
Lines will be created for the same Document No. as was used for the Sales Header. The next line no. will be found based on already available records with the created Document No. and with the selected Document Type.

It is also possible to use a function to select the next no. from a no.-series. Use the function code NOSERIES for this.
Using the SETTEMPVAL and GETTEMPVAL functions the No. value can be saved used later on in the definition.

IDYN 2024