I have a classname and a property name. I want to know, when I get object value directly from a global, which property corresponds to which position in the $lb structure.
Here's what I got so far:
Class Utils.Storage {
/// write ##class(Utils.Storage).GetPosition()
ClassMethod GetPosition(class As %Dictionary.CacheClassname = "Sample.Address", property As %Dictionary.CacheIdentifier = "Zip") As %Integer
{
set strategy = $$$comClassKeyGet(class, $$$cCLASSstoragestrategy)
set strategyId = class _ "||" _ strategy
&sql(SELECT Name INTO :position
FROM %Dictionary.StorageDataValueDefinition
WHERE parent = (SELECT ID
FROM %Dictionary.StorageDataDefinition
WHERE parent = :strategyId AND Structure = 'listnode')
AND Value = :property)
quit position
}
/// do ##class(Utils.Storage).Test()
ClassMethod Test()
{
set list = $lb("Street", "City", "State", "Zip")
set obj = ##class(Sample.Address).%New()
Do obj.%SetSerial(list)
set list2 = obj.%GetSerial()
zw obj, list2
}
}