Skip to Content
avatar image
Former Member

XPath Expression in REST Adapter

Hello Experts,

I'm trying to use substring function in XPath Expression for pattern replacement.

As per the below wiki I we can use it in Receiver Determination condition editor

https://wiki.scn.sap.com/wiki/display/XI/Xpath+Condition+in+Receiver+Determination

But when I tried to apply the same in Receiver REST adapter for Pattern Replacement using XPath Expression it's not working please guide me on this.

I trying to add query string for my REST URL dynamically using Pattern Replacement using XPath Expression

Expected URL: http://host:port/service/path?sid={SID}&recipient={RCVPRN}&sender={SNDPRN}

I've tried couple of ways but none of the giving expected results.

/INVOIC02/IDOC/EDI_DC40[substring(SNDPRN,1,3)]

/INVOIC02/IDOC/EDI_DC40[substring(//SNDPRN,1,3)]

/INVOIC02/IDOC/EDI_DC40[substring(SNDPRN,1,3)]/SNDPRN

I tried giving 1 argument to the substring function to check whether we can apply the function in xpath or not then I got below exception.

XPath: /INVOIC02/IDOC/EDI_DC40[substring(SNDPRN)]

"/INVOIC02/IDOC/EDI_DC40[substring(SNDPRN)]"; Message: "javax.xml.transform.TransformerException: com.sun.org.apache.xpath.internal.functions.FuncSubstring only allows 2 or 3 arguments - com.sun.org.apache.xpath.internal.functions.FuncSubstring only allows 2 or 3 arguments"

Which means we can apply this substring function but not sure how to pass xpath as an arugument(SNDPRN in my case) to the substring function

Note: I cannot use mapping here

Please guide me on this.

As ever,

Nagesh

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Dec 22, 2016 at 10:37 PM

    Hi Nageshwara,

    if you want the first 3 characters of SNDPRN you can use the below expressions.

    substring(//SNDPRN,1,3)

    substring(/ZPM_ORDER02/IDOC/EDI_DC40/SNDPRN,1,3)

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hello Navdeep,

      Tried that as well when I'm using - substring(//SNDPRN,1,3) it's giving below exception

      MP: exception caught with cause com.sap.aii.adapter.rest.ejb.parse.InvalidXPathExpression: Invalid XPath expression "substring(//SNDPRN,1,3)"; Message: "com.sun.org.apache.xpath.internal.XPathException: Can not convert #STRING to a NodeList! - Can not convert #STRING to a NodeList!"

      I think XPath Expression always expects start char with / or //.

      If I use - /INVOIC02/IDOC/EDI_DC40[substring(//SNDPRN,1,3)]

      It's giving null result form the xpath expression

      As ever,

      Nagesh

  • Dec 28, 2016 at 01:41 AM

    Hi NageswaraRao!

    Yes, it shouldn't work since you get NodeSet as result of your expression.

    Try this:

    substring(/INVOIC02[1]/IDOC[1]/EDI_DC40[1]/SNDPRN[1], 1, 3)

    Another syntax (if you have only one INVOIC02 element in your message):

    substring(/INVOIC02/IDOC/EDI_DC40/SNDPRN[1], 1, 3)

    Regards, Evgeniy.

    Add comment
    10|10000 characters needed characters exceeded