Indirectly traversing MultiDimensional properties

I can directly order over a MultiDimensional property, e.g.

set key=$order(obj.prop(key))

However I have a generic method that has to use the $property method, if I know the keys then I can just fetch a value with...

set value=$property(obj,"prop","key")

But if I don't know the keys then I am not aware of a solution to do this, e.g.

set key=$order($property(obj,"prop",key))

will not work.

There must be an internal solution as a zw command on obj is able to list all of the keys. I'm wondering if there is a $zu function or other trick that can do this. Any ideas?


  • 0
  • 0
  • 92
  • 4
  • 2


Hi Sean,
somewhat likely, using indirection instead of eXecute wink

 set %ref="obj."_prop,key="" for  set key=$order(@%ref@(key),1,val) quit:key=""  write key,?5,val,! 

Thanks Robert, I didn't realise indirection itself would work on an object property, far too obvious now, lol.

Hi. I was actually looking up some information about pattern matching, but came across this warning:

If a call attempts to use indirection to get or set the value of object properties, it may result in an error. Do not use calls of this kind, as they attempt to bypass property accessor methods (<PropertyName>Get and <PropertyName>Set). Instead, use the $CLASSMETHOD, $METHOD, and $PROPERTY) functions, which are designed for this purpose

This was from

So it looks like it may well work now, but there's no guarantee it will always work.

Surely there is a $method() call you can use to get the next item in the array?

Hi, Robert!

Just want let you know that we finally introduced one (ONE!) button for ObjectScript highlighting.  E.g. your code:

set %ref="obj."_prop,key="" for  set key=$order(@%ref@(key),1,val) quit:key=""  write key,?5,val,!

Can be highlighted like this:

Thanks, Evgeny:

Old eyes are hard on tiny things. wink

OK, so I guess I could use xecute for this...

xecute ("(obj,key) set key=$order(obj."_prop_"(key))",obj,.key)