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.

Can I get multiple rows from a datasource using datasource correlation?

Options
jefftuckerbofa
jefftuckerbofa Posts: 234

Can I get multiple rows from a datasource using datasource correlation? e.g. the datasource has multiple rows that have a column matching my xpath. Or, does that only work when there is a single match? Should I use scripting instead? Thanks JT

Comments

  • williammccusker
    williammccusker Posts: 645 ✭✭✭
    Options

    Hi,

    Data Source Correlation will use the first row that matches. So even if there are multiple matches it will only use the first one it finds. If you need to combine multiple rows of data together either scripting or using responder chaining are the options.

  • jefftuckerbofa
    jefftuckerbofa Posts: 234
    Options

    gotcha that's what I was seeing... I am trying to get an entire datasource in Groovy (instead of a single column). Is there a way to grab that from the context?

  • benken_parasoft
    benken_parasoft Posts: 1,235 ✭✭✭
    Options

    ScriptingContext has a "getValues" (plural) method. It works the same as "getValue" but returns a List of all values in a data source column. This can be useful in case you need your script to read all values in a data source as opposed to the values for the current row.

  • jefftuckerbofa
    jefftuckerbofa Posts: 234
    Options

    perfect

  • jefftuckerbofa
    jefftuckerbofa Posts: 234
    Options

    Is there any way to grab the datasource object from the context and use the data in my script?

  • benken_parasoft
    benken_parasoft Posts: 1,235 ✭✭✭
    Options

    The "context" lets you query data source contents by "dataSourceName" and "columnName" only.
    Some methods from com.parasoft.api.ScriptingContext:

    List<String> getValues(String dataSourceName, String columnName)
    String getValue(String dataSourceName, String columnName)
    
  • jefftuckerbofa
    jefftuckerbofa Posts: 234
    Options

    gotcha thanks! JT

  • jefftuckerbofa
    jefftuckerbofa Posts: 234
    Options

    so no way to muscle our way in and grab that entire datasource object in the context? ;-)

  • jefftuckerbofa
    jefftuckerbofa Posts: 234
    Options

    I decided to get the absolute filepath of the csv and read it into my Groovy script