Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Scripting Issue: Trying to get value in adjacent cell in Table Data Source

VirtEyes
VirtEyes Posts: 62

I have a script which is using a table data source within Virtualize. In that table there are two columns, num and ID. The value of num is extracted from the request via XML databank and is stored as a variable in the responder suite, titled key. Key = num
I have another variable that stored the ID value in a variable called id

The goal of the script is to look at the value of key, which is extracted fro the xml databank and stored on the responder suite level, match it with the list of numbers in the column num within the table. Once it makes a match, it will instead return with the cell next to it in the column to the right of num, ID

EX: request has key = 34, it should then go to the table, go through the column, num, and find value 34. Once found, return with the cell to the right of it, like ID = 42, and return that value.

So far I am using a Groovy script for it and am facing issues where the values for num are not lining up, therefore I am unable to extract the ID value from the table.
I am using the indexOf( ) function which I know worked in the past, but I am stumped on where I might be messing up in my code.
Could yall tell me whats wrong with my code, and / or what I may be missing for this?

code:
import com.parasoft.api.Application

def getID(input, context){
String key = context.getValue("Generated Data Source","key")
ArrayList Num = context.getValues("Num and ID","num")
ArrayList ID = context.getValues("Num and ID","ID")
int index = Num.indexOf(key)//key is the num extracted from the request
return id = ID.get(index)//getting the ID in the column
}

Comments

  • VirtEyes
    VirtEyes Posts: 62

    "Num and ID" is the name of the table data source btw

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,

    This sounds a lot like a Data Source Correlation. Is there a reason that Data Source Correlation cannot be used? Their purpose is to match values from the incoming request to a row in the data source so that other columns can be used in the response.

    https://docs.parasoft.com/display/VIRT9106/Understanding+How+Virtualize+Uses+Data+Sources

  • VirtEyes
    VirtEyes Posts: 62

    Hey William,

    Data source correlation would not work because there is no direct call from the request to the column in the table. Rather there is only a correlation based on the key which based on that value, should link up to an ID value in the table.

    So for instance, the request will come in for a number (ex: 32) and it is captured in the xml databank however, ID is never passed in the request. So I need to go to the table find where the value for number is (ex: row 4) and return with the ID in the column next to the one that has the value for number

  • VirtEyes
    VirtEyes Posts: 62

    Nope, nevermind, William is 100% correct.
    Data source correlation worked

    I was definitely overthinking it

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,

    You said that "ID is never passed in the request" but you also say that the "request will come in for a number" so I am not sure how that works. If you can data bank the value then you should be able to create a data source correlation for it.

    What are you attaching the XML Data Bank to? Incoming request? Transport header?

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,

    Glad to hear that Data source correlation did work! :smiley:

  • VirtEyes
    VirtEyes Posts: 62

    No I got it now, apparently I was confused with how I had it set up, calling the column of the ID's worked.

    the XML databank was attached to the incoming request

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Glad it worked! I had literally hit post as I got the notification about your comment that it worked :smiley: