Written by

Head of Supply Chain Strategy at InterSystems
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

Comments

Marc Mundt · Feb 11, 2022

One more way:

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

0
Steven Zerafa  Dec 20, 2022 to Marc Mundt

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

0