Alex Kogan · May 8, 2017

Can I return the status of the GUID override

I am using a method: %OverrideGuidAssignment("NEW GUID HERE") to override my GUID, and would like to know if there are any parameters, which allow this method to return a status & or error msg?
If you currently set it to a variable it returns the new GUID you originally passed in, regardless of if it failed to override or not.

Thank you in advance

0 311
Discussion (5)4
Log in or sign up to continue

Hello Alex,


Is this method part of your own custom class, or a system class?  If it is a system class, which one?

Hi Aaron,

This is a method inside Class %Library.GlobalIdentifier.

I realize it says in the comments: "The return value will only differ from the supplied value if the override is unsuccessful." - however in my testing, this is not the case.   You can put anything invalid in there - like the word "test", which is not valid GUID.  It will not replace the GUID with this invalid string, but it will not return the error message either.  You can also put non -unique GUID, which also will fail replacing (as it should), but will not return the error message. 

Here's the base implementation of this method in %Library.GlobalIdentifier (2017.1 version):

/// If a persistent class is GUIDENABLED then this method can be called to override the default GUID assignment.
/// This method accepts a guid value and returns the override value currently assigned. The return value will only
/// differ from the supplied value if the override is unsuccessful. It is only valid to call this method on a new object.
/// The guid value passed to this method is not validated. It is up to the user to make sure the guid is properly formed.
/// The guid assignment does not actually occur until the object is saved. If the object has already been assigned a GUID
/// or if the GUID override value has already been assigned to another object then the GUID override value will be discarded.
/// The check for GUID value uniqueness and a GUID value previously assigned is done only at the time the object is saved and is
/// not performed by this method.
Method %OverrideGuidAssignment(pGUID As %Library.CacheString) As %Library.CacheString
set i%"%%GUID" = pGUID
quit i%"%%GUID"

If I understand Alex correctly, he's calling this method in order to force a new instance of a GUIDENABLED class to have a specific GUID instead of getting one automatically assigned at save. He's not overriding the class in his own class definition.

I have highlighted in yellow some sentences in the comment that may be relevant.

I have also highlighted in pink the sentence Alex quoted, which is a bit unclear. By "return value" I think it means the GUID of the object instance after the save has subsequently been performed.

The way I see it working in 2017.1, %OverrideGuidAssignment only sets the in-memory value of the object's GUID to the value passed as the argument and returns the same value.  It does not validate the value.   If the object already has a GUID, it will not be changed.  New objects for which the user did not provide a GUID will have one assigned with $system.Util.CreateGUID() unless the user invoked %OverrideGuidAssignment(userGUID) before saving.

In order to know if the intended assignment was successful, you must compare it with the object's GUID after save to see if the assignment was successful or not.  If they are different, then it was not overridden, probably because it was not a new object.