Question
Guy Peer · Aug 28, 2017

Problem with inserting objects into a list in a business production

Hi,

I have a process in which i call a rest operation in a while loop, get a response in JSON format of 50 issues, with paging, meaning this call will happen until the total amount of issues will be returned. each JSON is parsed into a proxyObject, and inserted to a list. later the entire list will be sent to an SQL operation which will write the data in the appropriate tables.

The problem i'm encountering, is when i use the "ASSIGN" action, with insert at a certain key (context.i=context.i +1  for each iteration of the loop), i get an Error  that says that the value 3 is invalid key.

i've switched to "Append" and that error goes away, but in the operation when i iterrate through the object i get an invalid oref error.

set CountMain = pObject.IssuesList.Count()
for i=1:1:CountMain
{
       set CountRow=pObject.IssuesList.GetAt(i).Count()
       for j=1:1:CountRow
       {
             bla bla bla
       }
​}

i get INVALID OREF on set CountRow.

after a quick investigation I've found that  somehow i have more then one list.

if i set the loop to run twice, i have to object references of the list, so that's why value 3 is invalid because it's trying to set it at a position higher then plus one from the last full position.

Also noticed, that every time I go out of the scope of ENSEMBLE to an external class (NOT A SERVICE PROCESS OR AN OPERATION) all the context vars are some how reseted or get a new instance. 

what am I doing wrong? or for that matter is there a workaround for my issue?

Thank you,

Guy Peer

0
0 532
Discussion (6)1
Log in or sign up to continue
set CountRow=pObject.IssuesList.GetAt(i).Count()

you assume pObject.IssuesList.GetAt(i) gives back a %Collection Object (Iist, Array, ..)
Before applying method .Count() you should check if this assumption is true.

your previous description with ASSIGN / APPEND wasn't that convincing that you always have the object you expect.

ref: "out of the scope of ENSEMBLE to an external class" 
you should save anything that you want to keep over that call in one/multiple property of %context Object.


 

Okay, 

is the fact that the trace is on "context.MainObj" makes any difference?

i can't seem to grasp if after each response, i validate that i have an object returned, and i insert that object into the same context, how could it be that i get two different OREF's.

thought it might be something to do with how the ASSIGN action works, so i switched to a code block, in which:

set context.tempZenObj = tmpObj (the returned object from JsonToObject)

do context.MainObj.IssuesList.Insert(context.MainObj)

same result.

Hi Robert,

Thank's for the reply.

However, i do check to see if i get an object returned from JsonToObject, and i do insert it into a context that serves as a holder for the list.

i have a Class named MainObj which has a property of a list.

"Property IssuesList As list of %ZEN.ProxyObject"

and a context named MainObj of type MainObj.

do you have any explanation on why i have 2 instances of my context.MainObj?

Here's two screenshots of the trace which shows that it generates two instances.

 

you insert the object to itself ????

do context.MainObj.IssuesList.Insert(context.MainObj)

really ? does this make sense ??

I woldd expected something like:

do context.MainObj.IssuesList.Insert( tmpObj )

or

do context.MainObj.IssuesList.Insert(context.tempZenObj )

I'm sorry, that was a typo.

do context.MainObj.IssuesList.Insert(context.tempZenObj) is what i do.

The diagramm shows to me  2 object REFERENCES (oref)
oref consists of a  (local) integer@Classname  and points to an object.
in your case both are of type %Collection.ListOfObj 
by the reference you can't tell that this is the same.
any ##class(%Collection.ListOfObj).%New() will create a new oref
in your case I see a count of 1 and then a count of 2 
you should look what happens in or after (19)  and in or after (29)
looks to me like a fresh return value