Question
· Jul 25, 2017

How to automatically populate a transient array property?

Hi! I am trying to automatically populate an array property of cash amounts keyed by currency ("GBP", "USD", etc). This property needs to be NOT stored on the database and visible via SQL and the cache object. 

Here's my attempt. Ultimately the array will be populated based on the the some child classes, but for now I'm just hardcoding it:

 Property Amounts As array Of %Numeric [ SqlComputeCode = { set {*} = ##class(ContainerSize).GetTotalAmounts()}, SqlComputed, Transient ];
 ClassMethod GetTotalAmounts(thisID) As %Collection.ArrayOfDT
{
set arrAmounts=##class(%Collection.ArrayOfDT).%New()

do arrAmounts.SetAt(1.23,"GBP")
do arrAmounts.SetAt(2.45,"EUR")

quit arrAmounts
}

This compiles but accessing via SQL gives:

[SQLCODE: <-350>:<An unexpected error occurred executing SqlComputeCode>]

Via object:

macdocs:MACDEV1>w obj.Amounts
 
<INVALID OREF>zSetAt+4^%Collection.ArrayOfDT.1

If what I'm trying isn't possible, is there another datatype that I could populate with this kind of information, via compute code ?

Thanks!

Discussion (4)0
Log in or sign up to continue

From the documentation...

The %Collection.ArrayOfDataTypes class represents an array of literal (i.e., data type) elements, each of which is associated with a unique key value. Keys can have any value, string or numeric. These %Collection classes can only be used when you have a collection property of another object as they rely on storing the data inside the parent object, they can not be used as 'stand alone' collections, for this use the %ArrayOfDataTypes.