Forum Discussion

MMAKELA's avatar
MMAKELA
New Contributor
11 years ago

Setting request attributes to nil via Groovy

I have a data-driven Test Case which loads data from Excel via DataSource and then uses in the SOAP request message. Some of the fields loaded from Excel are Date values and sometimes the source data can contain blanks. However, my Web Service doesn't except blank values in field that expects xsd:date, so they should be dynamically changed to nil (xsi:nil = true).

Is it somehow possible via Groovy script to set certain elements to nil? I have already tried to set the property value to null, but that is only converted into blank element in the property expansion.

3 Replies

  • Hello,

    Try giving the Property a name and the value = null. Let me know if this works for you.

    Regards,
    Temil
  • MMAKELA's avatar
    MMAKELA
    New Contributor
    SmartBear Support wrote:
    Hello,

    Try giving the Property a name and the value = null. Let me know if this works for you.

    Regards,
    Temil


    This doesn't work as expected. My request looks like this:


    <cp:date-value>
    <cp:date>
    <com:value>${#TestCase#date1}</com:value>
    </cp:date>
    </cp:date-value>


    If I set the date1 property to null with Groovy, the generated request will contain a blank in the value element:

    <cp:date-value>
    <cp:date>
    <com:value></com:value>
    </cp:date>
    </cp:date-value>


    What I want to have is a nil value in the value element:


    <cp:date-value>
    <cp:date>
    <com:value xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
    </cp:date>
    </cp:date-value>
  • This Looks correct, it should work. We currently have a bug where the Request XML changes if you are using the Form View. try going to File>Preferences>SoapUI Pro and change the Default request Editor to Source. Let me know if this helps.

    Regards,
    Temil