Advanced Techniques - 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 set for an item of stock in a corresponding Intrexx
application, you can 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.)
with the unique number generator.
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 sets has the highest allocated number at
that point in time. When the data set is saved, a new number –
the previous highest increased by 1 – will be written into 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 following numbers.
Configure the datahandler
Create a new application in the Intrexx Portal Manager, based on the
Basic application template
From the context menu,
create a 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.
Display the data fields in the application structure, using the context
menu of the data group. Please
activate the expert options
if you have not done so already.
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 "datahanlder" attribute and click on OK.
Now you can include the Unique number field in the
table on the All Entries page
. Save the application.
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"?>
<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="###"/>
Create a new file with a standard text editor, and copy the above
code into the file. Amend the values referred to in the text 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 text 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 very simply from the
Extras / Create GUID
The GUID of the data field, where the unique number is to be generated,
can be identified with the F4 key, when you have selected the field
in the application structure.
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">
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 on this topic can be found in the
Save the file with the name "UniqueNumber.xml" in the
portal verzeichnis 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 types.
part type: constant
<part type="constant" value="UP-"/<
With the constant part type an arbitrary, fixed string value
can be generated.
part type: number
<part type="number" format="###"/<
The number part type generates an incremental number, that increases by 1.
The length of the number is controlled by the number of signs (#). 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
If the part type is of the Date/Time type, each portion of a date must be
created individually. All of the required part types from year through
month, day, hour, minute to second are available here.
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 is changed.
When using such a condition, however, it is important to ensure that
the Date/Time part types are placed in sequence from the strongest (year)
to the weakest (second).
<part type="year" condition="true"/>
<part type="month" condition="true"/>
<part type="day" condition="true"/>
With format="format entry", it is possible to customize the format of
the date/time components.
<part type="year" format="yyyy"/>
<part type="month" format="mm"/>
<part type="day" format="dd"/>