Official Content

This data type allows you to store GUID values.

GUID use is important when working in distributed environments.

GeneXus Internal use

GeneXus uses this data type internally to uniquely identify each type of object.

What for? The idea is that if an object is exported to another KB and modified there when it is later imported back to the source KB, the object will be identified as corresponding to the originally-exported object. Also, if an object is imported into a KB where an object with the same name but a different GUID already exists, GeneXus will know that even though they both have the same name, the imported object does not correspond to the existing object.

Generated applications use

In generated applications, there is a very similar need for using it. Imagine, for example, a POS (Point Of Sale) type application that works disconnected from the head office, where data is unloaded every night.

A common way to copy the data without having to modify the values of all the keys is to define a combined key that includes the number of the point of sale or branch terminal with the sale number.

Imagine the second or third level of this transaction. It will have a key including an attribute whose only purpose is to help make its key unique because there are many points of sale. Each time it is referenced in another transaction, all the key components must be present, generating unnecessary index maintenance.

Using the GUID data type, you can ensure a unique key and avoid this type of problem.

Its use is not limited to primary keys attributes nor records. It can also be used to help file generation (avoiding the duplication of same-name files), Site Keys generation, and any other cases where obtaining a globally unique identifier are required.

How is it used in GeneXus?

Static methods

  • GUID.NewGuid()
  • GUID.Empty()  
  • GUID.FromString(“XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX”)

Example

If &GUID <> GUID.FromString("2ac61739-b024-438e-a6e5-e507d8be4667")
     msg("Bad Site Key")
EndIf

Functions/ Instance methods

  • ToString() return a string with XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX format.
  • FromString() return GUID created by a hexadecimal string, with or without the "-" delimiters.
  • IsEmpy()
  • IsNull()
  • SetEmpty()
  • SetNull()

Example

&GUID.FromString("12daa4b3-d7c2-4df4-a634-18bed4f2374c")
msg("GUID: " + &GUID.ToString())

Autogenerate Guid property

Attributes and variables based on the GUID data type offer the Autogenerate Guid property to set that you want that the GUID value is automatically generated when an insertion is performed.

Scope

See Also

Initial value property

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