Question
Ming Zhou · Feb 11, 2022

How can I open an object with dynamic class name and id?

Similar to: "set obj = ##class(myClass).%OpenId(id)", which give the an instance of the object with given ID, is there a way to implement a function/classmethod to return the same by providing both class name and ID as a parameter, such as: getObjectInstanceByNameId(className As %String, id As %Integer), using ObjectScript code?

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

One more way:

s myObj = ##class(%Persistent).%Open($lb(id,className))

Thanks Marc. 

Is there another way to get the property value from myObj by providing the property name?

The only solution found is using %ZEN.Utils

s result = ##class(%ZEN.Utils).%GetPropertyValue(myObj, propertyName, .value)
w value