Question
· Oct 17, 2018

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?

Thanks,
Sean.

Discussion (6)2
Log in or sign up to continue

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 https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GCOS_operators#GCOS_operators_pattern

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?