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

Primary tabs

Ensemble

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.

Replies

Hi Jeff,

You're including "index" in the string. You would need to concatenate it in for it to take its value, such as:
set addarray(1) = source.GetValueAt("PIDgrpgrp(1).ORCgrp(1).OBXgrp("_index_".OBX:ObservationValue(1)")

Woohoo! Mr Sun, you are my hero.

I did have a close parenthesis to your example:

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

Thank you so much on this Friday afternoon. : )

Good catch, I accidentally deleted an extra character while adding the underscores. Happy to help!

I did also comment on your post from last week with an example of a loop - I hope that can give you some ideas as well.

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?

Where does J get set? Your loop is setting h from 1:1:x. Perhaps you want to use h instead of J.

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.


    

    
 

Hi Jeff,

Perhaps you are using shorthand and I would need to see a larger sample of your code, but in your actual code are you using SetValueAt? If you're transforming HL7 messages you will need to use that method.

SetValueAt is the other side of the GetValueAt coin.

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)")) 
    
        }

Glad I could help!

You might find the following documentation helpful as well:

Virtual Property Paths

I have always found it useful to experiment with virtual property paths in the terminal as is explained in the bottom section of that page.