Forum Discussion

scorpionawal's avatar
scorpionawal
Occasional Contributor
14 years ago

If the source is missing, the transferred property is null,

Hi Guys,

If the source is missing, the property transfers value=null but I need 0 to be transferred in this case.
The xml response is:

<Results>
<ResultSet fetchSize="10">
<Row rowNumber="1">
<FROM>66850117700</FROM>
<TO>66860111113</TO>
<SUM>20</SUM>
<COUNT>2</COUNT>
</Row>
<Row rowNumber="2">
<FROM>66950117777</FROM>
<TO>66860111114</TO>
<SUM>30</SUM>
<COUNT>3</COUNT>
</Row>
<Row rowNumber="3">
<FROM>66950117777</FROM>
<TO>66860111113</TO>
<SUM>40</SUM>
<COUNT>4</COUNT>
</Row>
<Row rowNumber="4">
<FROM>66850117700</FROM>
<TO>66860111114</TO>
<SUM>20</SUM>
<COUNT>2</COUNT>
</Row>
</ResultSet>
</Results>


and I am trying to transfer

//Results[1]/ResultSet[1]/Row[FROM="66850117700" and TO="66860111111"]/number(SUM)
into a property

Please note that this source does not exist in the response. So Property being transferred is null.
And if I untick the option, I get an error "Missing source for blah blah".

Can I transfer a number, like 0, in this case. I have tried it with number(above expression) but then I get NaN.

Any help will be appreciated.
Regards
Amit
  • deepesh_jain's avatar
    deepesh_jain
    Frequent Contributor
    Hi Amit,

    What you can do is get the xml in xml holder and check for the count of the tag in question. In case the count is 0, you can set desired property as 0. Here is how:

    def groovyUtils1 = new GroovyUtils (context) ;
    def holder = groovyUtils1.getXmlHolder("<Step_Name>#Response") ;
    def tagCount = holder["count(//Results[1]/ResultSet[1]/Row[FROM="66850117700" and TO="66860111111"]/number(SUM))"];
    if (tagCount == 0)
    {
    //set desired property as 0
    }


    Let me know if this helps.

    Regards,
    Deeepsh Jain
  • deepesh_jain's avatar
    deepesh_jain
    Frequent Contributor
    Or what you can do is set all properties as 0 one time manually. And then remove check from "Set Null on missing source" and check "Ignore empty/missing values"
  • scorpionawal's avatar
    scorpionawal
    Occasional Contributor
    Hi Deepak,

    thanks for the solutions. I tried 2nd method and it worked for me.

    Regards
    Amit
  • scorpionawal's avatar
    scorpionawal
    Occasional Contributor
    deepesh.jain wrote:
    Hi Amit,

    What you can do is get the xml in xml holder and check for the count of the tag in question. In case the count is 0, you can set desired property as 0. Here is how:

    def groovyUtils1 = new GroovyUtils (context) ;
    def holder = groovyUtils1.getXmlHolder("<Step_Name>#Response") ;
    def tagCount = holder["count(//Results[1]/ResultSet[1]/Row[FROM="66850117700" and TO="66860111111"]/number(SUM))"];
    if (tagCount == 0)
    {
    //set desired property as 0
    }


    Let me know if this helps.

    Regards,
    Deeepsh Jain





    Hi Deepak,

    I tried the first method also. But I get an error message

    startup failed: Script8.groovy: 1: unable to resolve class GroovyUtils @ line 1, column 20. def groovyUtils1 = new GroovyUtils (context) ; ^
    org.codehaus.groovy.syntax.SyntaxException: unable to resolve class GroovyUtils @ line 1, column 20.
    at org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:148) at
    ------------
    ------------

    What am I missing.?

    Regards
    Amit
  • deepesh_jain's avatar
    deepesh_jain
    Frequent Contributor
    Hi Amit,

    Did you import "com.eviware.soapui.support.GroovyUtils" in your groovy script at the top?

    Regards,
    Deepesh.
  • scorpionawal's avatar
    scorpionawal
    Occasional Contributor
    Hi Deepesh

    You are right. I was not importing the package. I am new with the scripts.

    But importing the package has solved the problem. Can you please tell me where can I find more help on Groovy script and script assertion

    Regards
    Amit
  • deepesh_jain's avatar
    deepesh_jain
    Frequent Contributor
    Hi Amit,

    Short answer to your question is google . Long answer is depends what you are looking for. Try going through the soapui features section for more information. Also, you can get some help on groovy.codehaus.org. If you have any specific question related to groovy scripting, you can try searching in this forum itself or you can reach out to me. If possible, I might be able to help you. Send me a Private Message with your location and other details, we might get in touch.

    Regards,
    Deepesh Jain