Tips & Tricks - Unique number generator
The unique number generator makes it possible to generate automatically incrementing numbers according to predefined criteria. In these cases, the number can consist of any required combination of parts (number, date, time, word). The best known examples of unique numbers are probably inventory numbers. When creating a data record for an item of stock in a corresponding Intrexx application, you can use the unique number generator to generate numbers that are continuous and incremental, and are constructed according to a defined syntax (e.g. Inv-2013-06-0001, Inv-2013-06-0002, etc.). It also makes sense to use the unique number generator for orders, parts lists or customer numbers. Unique numbers can be generated via the data handler of a data field. A check is made before the record is saved, to determine which unique number in the previously saved data records has the highest allocated number at that point in time. When the data record is saved, a new number – the previous highest plus 1 – will be written to the data field. A sequential number assignment is guaranteed with this method. Even if the portal service is restarted, the highest allocated unique number will be determined and used as the basis for calculating the subsequent numbers.
Configure the datahandler
Create a new application in the Intrexx Portal Manager based on the Basic application template. Create a new data field in the data group. Since values with Date, Integer and String format can be included in a unique number, please use data fields with the "Short text" data type only. Do not place a unique number in a system data field. Only use data fields that you have created yourself. Assign the title "Unique number" here.
Open the properties dialog of the "Unique number" data field by double-clicking on it and then switch to the "Expert" tab. Enter the value
in the "datahandler" attribute and click on "OK".
Create the UniqueNumber.xml file
The UniqueNumber.xml file contains the definition of all unique numbers in the current portal.
<?xml version="1.0" encoding="UTF-8"?><uniquenumbers> <uniquenumber name="myUniqueNumber1" guid="guid" link-datafield="guid"> <part type="constant" value="UP-"/> <part type="year" condition="true" format="yyyy"/> <part type="month" condition="true" format="mm"/> <part type="day" condition="true" format="dd"/> <part type="constant" value="-"/> <part type="number" format="###"/> </uniquenumber></uniquenumbers>
Create a new file with a standard text editor, and copy the code above into the file. Amend the values below as follows:
Name of the relevant unique number (freely selectable, must be unique)
GUID of the relevant unique number (freely selectable, must be unique)
GUID of the string data field where the unique number will be generated
- <part .../>
Definition of a part of the unique number
Enter a name for your unique number in "name". A GUID for the unique number can be generated easily via the Extras menu / Create GUID. To identify the GUID of the data field, where the unique number will be generated, select the data field in the application structure and press the F4 key. In the UniqueNumber.xml file, you can define as many unique numbers as you require. For additional unique number definitions, copy this section
<uniquenumber name=" myUniqueNumber1" guid="guid" link-datafield="guid">... </uniquenumber>
and replace the entries for "name", "guid", "link-datafield" and the "part types" with the corresponding new values. In the "part-type" tags that follow, you can specify one part of the unique number in each tag. In our example here, the new number begins with "UP-", followed by the four-digit year, the month, the day, a hyphen and a three digit number that is automatically incremented. More information about this is available in the next chapter. Save the file with the name "UniqueNumber.xml" in the portal directory internal/cfg. Now the portal service needs to be restarted. You can see the result in the browser below.
The individual parts of a unique number and their ordering are defined by the different "part type" elements.
part type: constant
<part type="constant" value="UP-"/<
Generates a fixed string value of your choice.
part type: number
<part type="number" format="###"/<
Generates an incremental number that increases by 1 each time. The length of the number is controlled by the number of hash characters (#). Thus, format="###" generates three digit numbers for the numeric part of the unique number in the series 001, 002, 003, etc. If the maximum number is reached (in this example 999), the sequence is restarted from 001.
part type: date/time
Each part of the date/time must be created individually. All of the required part types from year through month, day, hour, minute to second are available here.
<part type="year"/> <part type="month"/> <part type="day"/> <part type="hour"/> <part type="minute"/> <part type="second"/>
If a condition is used with the date/time part types (year, month, day, hour, minute and second), then the number part of the unique number will restart from 1 if one of the corresponding date/time parts change. When using such a condition, however, it is important to ensure that the date/time part types are placed in sequence from the highest (year) to the lowest (second).
<part type="year" condition="true"/> <part type="month" condition="true"/> <part type="day" condition="true"/>
The "format" option allows you to customize the format of the date/time parts.
<part type="year" format="yyyy"/> <part type="month" format="mm"/> <part type="day" format="dd"/>