Question
· Apr 11, 2022

Is it possible to add an index to a %SerialObject property?

I have a %Persistent class with properties that are of %SerialObject. I want to add an index to a property of the %SerialObject class.

Is this possible?

Product version: IRIS 2021.1
Discussion (3)1
Log in or sign up to continue

Yes. Here's a quick sample:

Class DC.Demo.SerialObject Extends %SerialObject
{

Property foo As %String;

Property bar As %String;

}

Class DC.Demo.IndexOnSerialObject Extends %Persistent
{

Property blah As DC.Demo.SerialObject;

Index blahFooBar On (blah.foo, blah.bar);

ClassMethod RunDemo()
{
    Do ..%KillExtent()
    Set inst = ..%New()
    Set inst.blah.foo = "foo"
    Set inst.blah.bar = "bar"
    Do inst.%Save()
    zw ^DC.Demo.IndexOnSerialObjectD,^DC.Demo.IndexOnSerialObjectI
}

}

Which produces output:

d ##class(DC.Demo.IndexOnSerialObject).RunDemo()
^DC.Demo.IndexOnSerialObjectD=1
^DC.Demo.IndexOnSerialObjectD(1)=$lb("",$lb("foo","bar"))
^DC.Demo.IndexOnSerialObjectI("blahFooBar"," FOO"," BAR",1)=""