Forum Discussion

omensio's avatar
omensio
Contributor
15 years ago

How to make multiple same elements into request from datasource

Hi!
Waht is the best way to make multiple same elements, eg.

FI
Finlad

SE
Sweden  //(in Excel is colums for code and name)
..
dynamically from Excel into the request. Key poit here is that we do not know how many elements to add, so perhaps property transfer or expansion are not suitable for the job.

Prpbably i need to make a script ? I appriciate to have a example  ;-).

BR,
Olli

4 Replies

  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    I have used a Datasource / Datasource Loop with a Groovy step between which appended the Datasource elements to a property, then used the property after exiting the loop.

    def gu = new com.eviware.soapui.support.GroovyUtils( context )

    def countryCode = context.expand( '${DataSource#CountryCode}' )
    def countryName = context.expand( '${DataSource#CountryName}' )

    def frag = context.expand('${Properties#XmlFragment}')

    gu.setPropertyValue('Properties', 'XmlFragment', "${frag}<country><code>${countryCode}</code><name>${countryName}</name></country>" )


    Resulting XML in Properties#XmlFragment:

    USUnited StatesFIFinland


    There are other ways to do this in script but this is pretty simple.
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Nice solution!

    we should put this in our knowledgebase somehow.. hm.. :-)

    regards!

    /Ole
    eviware.com
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    Maybe there should be an "Aggregator" - a template that can contain the elements from a row of a DataSource which then automagically loops through it to produce the repeating elements.