Datatype class for global reference
Is there a datatype class with validation for global references? I can't find one in a brief scan of the documentation / class reference.
Discussion (4)2
Comments
In the possible absence of a built-in class for such a purpose, this seems to work:
Class DC.Demo.GlobalReference Extends %String [ ClassType = datatype ]
{
/// 511 is an upper bound for the maximum length of a global reference - see:
/// <a href="https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GGBL_structure#GGBL_structure_maxsubscrlen">Maximum Length of a Global Reference</a>
Parameter MAXLEN = 511;
ClassMethod IsValid(%val As %CacheString) As %Status [ ServerOnly = 0 ]
{
Set tOldZReference = $ZReference
Set tSC = $$$OK
Try {
Set $ZReference = %val
} Catch e {
// The above SET will throw a <SYNTAX> exception for an invalid global reference
Set tSC = $$$ERROR($$$GeneralError,$$$FormatText("Invalid global reference: %1",%val))
}
Set $ZReference = tOldZReference
Quit tSC
}
}How about using $Name() function?
Thanks for pointing that out, but it's not really ideal for my use case, since it's not a % class and explicitly documented "Only to be used in the context of DataCheck." I think I'd also like to permit extended global references, which my original approach does.