🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators newGuid
This page was created by Stephanie on 2025-01-08. Last edited by Wikiadmin on 2026-07-29.

You can use newGuid() in an EAL expression to generate and store a new GUID in a Guid-type attribute, for example when an object is created.

Purpose

A GUID is a globally unique identifier that you can use to identify an object across time and between systems. Use newGuid() on the Guid attribute that will hold the identifier.

The operation creates a new GUID and stores it in the attribute on which you call it.

Syntax

self.Guid.newGuid()

In this example, self is the current object and Guid is a Guid-type attribute on that object.

Use newGuid when an object is created

A common use is to assign an identifier in an OnCreate method.

  1. Add a Guid-type attribute named Guid to the class.
  2. Create or edit the class's OnCreate method.
  3. Add the following expression to the method body:
self.Guid.newGuid()

When an instance of the class is created, the expression assigns a new GUID to its Guid attribute.

Example: object identity superclass

The object identity pattern uses a default superclass to provide a GUID and creation timestamp for objects in a package. Its OnCreate method body is:

CreateTime:=DateTime.Now;
self.Guid.newGuid()

This assigns the current date and time to CreateTime and generates a GUID for Guid. Classes that use that superclass receive these values when they are created.

Requirement and limitation

Call newGuid() only on an attribute of type Guid. The Guid attribute must not be null when you use this expression.

Use the operation when you need a new identifier. Do not use it when you need to preserve an existing identifier, for example when retaining the identifier of an object that is being tracked or exchanged with another system.

See also