Question
· Mar 12, 2018

Persistent table with %GUID As property

How to set the property 

 Property myguid As %GUID [ Required ];

S obj=class object

S obj.myguid ="guid string"

Discussion (3)1
Log in or sign up to continue

do you look for $System.Util.CreateGUID() ?
http://docs.intersystems.com/latest/csp/documatic/%25CSP.Documatic.cls?PAGE=CLASS&LIBRARY=%25SYS&CLASSNAME=%25SYSTEM.Util#METHOD_CreateGUID

Property myguid As %GUID Required ];

Will not work as %Lbrary.GUID is an abstract utility class and does not extend %DataType.  So it is no DataType and has no Accessors!
http://docs.intersystems.com/latest/csp/documatic/%25CSP.Documatic.cls?PAGE=CLASS&LIBRARY=%25SYS&CLASSNAME=%25Library.GUID

use instead.:

Property myguid As  %String  [Required];

and

S obj.myguid = $System. Util.CreateGUID()

But you are free to define your own data type combining %String and %GUID

You can also try overriding the GUIDENABLED parameter from %Persistent:

Class User.Test1 Extends %Persistent

{

Parameter GUIDENABLED = 1;

Property Property1 as %String;

Storage Default

{

<Data name="Test1DefaultData">

<Value name="1">

<Value>%%CLASSNAME</Value>

</Value>

<Value name="2">

<Value>Property1</Value>

</Value>

</Data>

<DataLocation>^User.Test1D</DataLocation>

<DefaultData>Test1DefaultData</DefaultData>

<IdLocation>^User.Test1D</IdLocation>

<IndexLocation>^User.Test1I</IndexLocation>

<StreamLocation>^User.Test1S</StreamLocation>

<Type>%Library.CacheStorage</Type>

}


}

Will give you:

USER>set obj = ##class(Test1).%New()

USER>set obj.Property1 = "Hello"

USER>w obj.%Save()

1

USER>w obj."%%GUID"

FC381F94-277E-11E8-82F0-005056B479AA

The ^OBJ.GUID index that this creates can be accessed via %ExtentMgr.GUID.