Forum Discussion

agupta1's avatar
agupta1
Contributor
16 years ago

Proeprty expansion context.expand

I have the following in a groovy script:

def email = "jilldoe-Taj@testcorp.yal.avaya.com"

def guid = context.expand( '${GetVoiceItems#Response#//ns1:getVoiceItemsResponse[1]/ns1:getVoiceItemsResult[1]/ns1:SRVoiceItem[//ns1:Email=${email}]//ns1:Identifier}' )
log.info("guid = " + guid);

Please note the [//ns1:Email=${email}]. However this does not set the guid. Instead if I copied the literal ("jilldoe-Taj@testcorp.yal.avaya.com") I get the guid.

What am I doing wrong?

Thanks

Anshu

7 Replies

  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    I think you might have 2 problems

    1) You should use GetVoiceItems#ResponseAsXml

    2) You are trying to do a context expansion and a gstring replacement at the same time... the context.expand wants single quotes (') while the gstring replacement wants double quotes("). Maybe not the best solution, but if you make put the email value into a property and reference that it may work:

    [tt:28o6irac]def guid = context.expand( '${GetVoiceItems#Response#//ns1:getVoiceItemsResponse[1]/ns1:getVoiceItemsResult[1]/ns1:SRVoiceItem[//ns1:Email="${Properties#email}"]//ns1:Identifier}' )[/tt:28o6irac]
  • I did try the suggestion but it didnt work.

    Any other suggestions...?
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    Can you show the actual response XML that you are trying to work with?

  •  
         
           
               
                  0ca9bf654ba08e439b0252286216fece
                  UnitTest Taj
                  UnitTest
                  Taj
                  5104
                  UnitTest-Taj@testcorp.yal.avaya.com
                  5104
                  5104
             


         

     
  • An easier way of dealing with the GString replacement issue is to use this instead:


    def email = "jilldoe-Taj@testcorp.yal.avaya.com"

    def guid = context.expand( '${GetVoiceItems#Response#//ns1:getVoiceItemsResponse[1]/ns1:getVoiceItemsResult[1]/ns1:SRVoiceItem[//ns1:Email='+email+']//ns1:Identifier}' )
    log.info("guid = " + guid);


    Regards,
    Dain
    eviware.com
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    Thanks Dain. That's a better way.

    Trying it out I see that double quotes are needed around the email address:

    [tt:2o1cewov]...[//ns1:Email="'+email+'"]...[/tt:2o1cewov]

    otherwise I get a Saxon exception:

    Caused by: net.sf.saxon.trans.XPathException: XPath syntax error at char 101 on line 2 in {...est-Taj@testcorp.yal.avaya....}:
          expected "]", found "@"