cancel
Showing results for 
Search instead for 
Did you mean: 

how to store repeated elements in an array

Occasional Contributor

how to store repeated elements in an array

I have 2 responses , one SOAP and one REST. I need to compare the two values and check if they match . I created an an array to store the SOAP taxlots but when I try to log it, it gives an error

 

so SOAP response is something like this .  

 

Security 1

      Taxlot 

      Taxlot

Security2

     Taxlot

Security3

     Taxlot 

  

REST response is 

 

Security 1Taxlot

Security 1Taxlot

Security2 Taxlot

Security3 Taxlot

 

 

I have been able to read the taxlots for each security in SOAP. I want to store them in a matrix

something like taxlot[1], taxlot[2]...

The number of taxlots are dependent on another field called row count. So I want to use a for loop and store the values .

 

I tried something like below

secIndex is for security count

taxlotids is the number of taxlot for each security

j is to store the taxlots in an array

 

 

 


def j=0 

for (def secIndex=1;secIndex<val;secIndex++)
{
def securities=holder.getNodeValues( "//glSmiley FrustratedampleResponse/SecurityList/SecurityInformation[$secIndex]/SecurityNumber[1]")


log.info securities.toString()  // logs the security number

 

def taxlotids =holder.getNodeValues( "//glSmiley FrustratedampleResponse/SecurityList/SecurityInformation[$secIndex]/TaxLotList[1]/TaxLotInformation").length


log.info taxlotids // logs the number of taxlots for each security 

 

int taxlotidsi=taxlotids+1

def matrix= []

 

for (def ti=1;ti<taxlotidsi;ti++)

{

def termval= holder.getNodeValues( "//glSmiley FrustratedampleResponse/SecurityList/SecurityInformation[$secIndex]/TaxLotList[1]/TaxLotInformation[$ti]/GainLossForTaxLot[1]/Term[1]" )   // This gets the Taxlotfield

 

 

matrix[j]=termval  //Creating an array to store these taxlots. Not sure if its the right way


log.info matrix[j].toString() 


j++  //incrementing the array counter
log.info j
}
}

 

log.info matrix[2]   ------ I want to log the value of second taxlot but this gives an error

1 REPLY 1
Community Hero

Re: how to store repeated elements in an array

Some would be able help you or give pointers if you can show the data.


Regards,
Rao.
New Here?
Join us and watch the welcome video:
Watch the new Interview
Top Kudoed Authors