Question
· May 18, 2018

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
Log in or sign up to continue

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
}

}