Udostępnij za pośrednictwem


GUID Data Type

Assigns a unique identifying number to any database object. The GUID data type is a 16 byte binary data type. This data type is used for the global identification of objects, programs, records, and so on. The important property of a GUID is that each value is globally unique. The value is generated by an algorithm, developed by Microsoft, which assures this uniqueness.

The GUID is a 16-byte binary data type that can be logically grouped into the following subgroups:

4byte-2byte-2byte-2byte-6byte.

The standard textual representation is {12345678-1234-1234-1234-1234567890AB}.

The virtual table OLE Control (2000000042) does not use the GUID data type. It uses a textual representation of the GUID in a text field instead. It is easier to make operations and references to this text field using the GUID data type than it is using the textual representation. The GUID data type is compatible with the existing textual representation.

The GUID data type is useful when you want to uniquely identify some data, so that it can be exchanged with external applications. For example, if you want to transfer an item catalog to an external application, you add a GUID field to the record in the table and use this as the primary reference when you communicate with the external application.

Compatibility

You can assign and compare the Text data type and the GUID data type. Assigning a GUID to a Text can be done as follows:

MyTableRec.MyGuid  :=  MyTableRec.MyText;

Useful C/AL Functions and Properties

The following C/AL functions can be used with the GUID data type:

Guid:=CREATEGUID();

This function creates a new unique GUID value. The value can then be assigned to a field of the GUID data type or of the Text data type.

Ok:=ISNULLGUID(Guid);

This function is a convenient way to check if a value has already been assigned to a GUID. A NULL GUID (consisting only of zeroes) is valid, but should never be used for reference purposes.

CLEAR(Guid);

The standard CLEAR function can also be used on the GUID data type. It nullifies the GUID.

AutoSplitKey

A NULL GUID is valid but is not useful in a table. Therefore, the AutoSplitKey property is implemented for the GUID data type when it is used in a page. When GUID is selected as a primary key, AutoSplitKey is enabled for the page, and the GUID value remains NULL. When you create a new record, a valid GUID is created and assigned automatically.

The CREATEGUID Function (GUID) and ISNULLGUID Function (GUID) functions are available in the C/AL Symbol Menu under SYSTEM, Variables.

CREATEGUID takes no arguments and returns a valid 16-byte GUID value. If the result is assigned to a TEXT variable or field, the value is converted to a string and follows the syntax explained earlier. The algorithm that generates the new GUID value uses Microsoft's CoCreateGuid function.

ISNULLGUID takes a GUID value as a required argument and returns TRUE/FALSE depending on whether the GUID value is NULL. This function does not accept a Text value as an argument.

CLEAR is the standard CLEAR function and takes one required argument. It nullifies the GUID value in the same way as it resets any other value.

AutoSplitKey is a property, not a function and can be applied to pages. If you have defined a GUID field as part of the primary key, the AutoSplitKey property automatically generates a new valid GUID value. When a new record is created and the GUID field is left as NULL, the AutoSplitKey property ensures that a valid GUID value is automatically inserted into the field. If you then enter a NULL GUID into this record, for example, by using the CLEAR function, this new NULL GUID value is not automatically replaced by the AutoSplitKey property. The AutoSplitKey property only applies to new records.

Format

The GUID value can also be represented as text. You can use the standard C/AL functions FORMAT and EVALUATE to convert from GUID values to Text values. If you do not use the correct format when you edit a GUID value in its textual format, the following error message is displayed:

Invalid Format of GUID string. The correct format of the GUID string is {CDEF7890-ABCD-1234-ABCD-1234567890AB} where 0-9, A-F symbolizes hexadecimal digits.

See Also

Reference

CREATEGUID Function (GUID)
ISNULLGUID Function (GUID)