Question
· Jul 17, 2020

Ensemble - Action/Code not populating an array from a GetValueAt using a variable

Hi, I'm still very much new at Ensemble DTL.  I am trying to set up an algorithm that requires loading fields from an OBX into an Array.  I don't think that I know how to iterate through the OBXs.  I know that there is a "for loop", that I will try to play with, but in the mean time, could someone tell me what is wrong with the following?

For example the code below works when I hard code the number 1 in OBXgrp(1)

 

 set addarray(1) = source.GetValueAt("PIDgrpgrp(1).ORCgrp(1).OBXgrp(1).OBX:ObservationValue(1)")
 
 write addarray(1)

 

I get the value that I expect. However, when I run the code with the variable "index" in the OBXgrp below:

 set index = 1
 set addarray(1) = source.GetValueAt("PIDgrpgrp(1).ORCgrp(1).OBXgrp(index).OBX:ObservationValue(1)")
  
 write addarray(1)

 

Nothing appears.  How can I use variables in the source.GeValueAt? And by the way, what should I be calling this?

 

I realize that this may not be the best, slickest, way to do this. But since I don't understand the many nuances of Objectscript and DTL just yet, I'd like to stick to code that I can comprehend and implement and then backfill knowledge later.

Discussion (9)1
Log in or sign up to continue

Can I ask you one more question? I want to put data from my array into the OBX 5 field. So data from myArray(1) would go into the first OBX line, and data from myArray(2) would go into the second OBX line, etc. . .

I am using a "code" action in DTL. 

So myArray has "x" number of elements. I want myArray(J) to be written into the Jth line of the OBX.

    for h = 1:1:x
        {

            set target("PIDgrpgrp(1).ORCgrp(1).OBXgrp("_J_").OBX:ObservationValue(1)") = myArray(J)
    
        }

Unfortunately all I get it to do is write the same value in myArray(1) in every OBX segment.  What is the correct syntax?

Sigh. Yes, you are right. I was rushing to write that.  OK, I'll try again.  "J" is just the index number iterating through the particular OBX field, "finished" is the number of the last element in the array called my reorderedAddendaOBXArray() .  

I use the "write" command while troubleshooting, so I know that my array is constructed exactly how I want it. 

 for J = 1:1:finished

 { write reorderedAddendaOBXArray(J)}

prints in my test function the all the contents of the array just nicely.

I just don't know how to feed the data that is in the array back into OBX 5.  I've tried many different ways, and I hope that I can just set up a code 

    set J = 1        
    
    for J = 1:1:finished
        {

            set target("PIDgrpgrp(1).ORCgrp(1).OBXgrp("_J_").OBX:ObservationValue(1)") = reorderedAddendaOBXArray(J)
    
        }

Please help. I promise this will be my last response as I've wasted your time too much already.

Thank you so much for your help. Seriously, it is very much appreciated.  The SetValueAt method was what I was missing.  I read through an exchange that you had with someone else about two months ago about an almost identical question.  I knew what I wanted, I guess I was just struggling with the syntax of DTL.  Anyway, in case you are curious what this last snippet was, here it is.

    set J = 1        
    
    for J = 1:1:finished - 1
        {

            set whatever=target.SetValueAt(reorderedAddendaOBXArray(J),("PIDgrpgrp(1).ORCgrp(1).OBXgrp("_J_").OBX:ObservationValue(1)")) 
    
        }