Convert %ArrayOfDataTypes to array, and back again
Here's an easy one for you; before I spend another hour looking for the answer, how do you convert %ArrayOfDataTypes to an array (that could, say, fit into the %session.Data array, or maybe just some array named info()), and of course back again?
NS>s aodt=##class(%ArrayOfDataTypes).%New()
NS>w aodt.SetAt("lcavanaugh","username")
1
NS>w aodt.SetAt("organization","coolcompany")
1
NS>w ##class(%ArrayOfDataTypes).BuildValueArray(aodt,.array)
<LIST>zBuildValueArray+1^%Library.ArrayOfDataTypes.1
aodt must be serialzed. What?
NS>zw array
NS>
There isn't a built-in method that does exactly what you're looking for, that I know of. Here's a simple example of how to do it, though:
Usage:
If you really wanted to make BuildValueArray work:
The utility method approach would probably at least be clearer.
Ooh, fun, thanks. Can I use it with %ListOfDataTypes too? I have both returned from methods, and I need to use them in the %session array.
ArrayObjectToArray happens to also work with %ListOfDataTypes, but ArrayToArrayObject won't as written, because %Library.ListOfDataTypes:SetAt only allows changing existing keys. You could write a similar method for lists that uses Insert() rather than SetAt().