Forum Discussion

LucMertensSteri's avatar
LucMertensSteri
New Contributor
12 years ago

Property trransfer .... For Each

I have the following request structure:
<!--1 or more repetitions:-->
<SmartMeterMeterReadingDocumentERPCreateRequestMessage>
<ID>ID1-${=new java.text.SimpleDateFormat("MMddHHmmss").format(new Date())}</ID>
</SmartMeterMeterReadingDocumentERPCreateRequestMessage>
<SmartMeterMeterReadingDocumentERPCreateRequestMessage>
<ID>ID2-${=new java.text.SimpleDateFormat("MMddHHmmss").format(new Date())}</</ID>
</SmartMeterMeterReadingDocumentERPCreateRequestMessage>

this way, we assure a unique ID, even when the test is repeated.

But this ID is reused in another query, also containing 2 rows:
<!--1 or more repetitions:-->
<SmartMeterMeterReadingDocumentERPBulkCancellationRequestMessage>
<ID>Must Be ID 1</ID>
</SmartMeterMeterReadingDocumentERPBulkCancellationRequestMessage>
<SmartMeterMeterReadingDocumentERPBulkCancellationRequestMessage>
<ID>Must be ID 2</ID>
</SmartMeterMeterReadingDocumentERPBulkCancellationRequestMessage>

We have to replace these IDs by the value of the IDs used in the first request

I can do it with 2 property transfers indicating the number in square roots.
//.../SmartMeterMeterReadingDocumentERPCreateRequestMessage[1]/ID
This works and is a solution. For every row, I can write a property transfer.

But the number of rows can be dynamic in other examples, and the number of rows can be large (up to 1000).
Is there a way to encode this loop automatically?

Thanks for your help

Luc

2 Replies

  • Thanks Rao,

    based on your comment, I wrote this code and it works fine:

    //declare namespace soapenv="http://schemas.xmlsoap.org/soap/envelope/";
    //declare namespace glob="http://sap.com/xi/SAPGlobal20/Global";

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def holderIn = groovyUtils.getXmlHolder( "Create request With Var#Request" )
    def holderOut = groovyUtils.getXmlHolder( "Cancel with parameter#Request" )
    // loop item nodes in response message


    def aantal = holderIn["count(//MeterReadingDocument/ID)"]
    log.info "aantal: $aantal"
    def teller = 0
    for( item in holderIn.getNodeValues( "//MeterReadingDocument/ID" ))
    {
    teller = teller + 1
    holderOut.setNodeValue("//soapenv:Envelope/soapenv:Body/glob:SmartMeterMeterReadingDocumentERPCancellationRequest/MeterReadingDocument/ID[$teller]",item)

    }