cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

XPath Expression in REST Adapter

nageswararao_v2
Participant
6,911

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

Accepted Solutions (0)

Answers (5)

Answers (5)

Snavi
Active Participant

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)

nageswararao_v2
Participant
0 Likes

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

0 Likes

Hello,

How were you able to fix the issue?

LeonrdoLemos
Explorer
0 Likes

try this note: 2793544 - REST Receiver cannot evaluate

vicky20691
Active Contributor
0 Likes

Hi,

There is a strange thing about REST that in RECEIVER adapter it takes the receiver payload and not the sender payload so map the SNDPRN to one field in receiver structure and then do xpath. Or go For adapter specific attribute (ASMA).
https://blogs.sap.com/2014/12/18/pi-rest-adapter-using-dynamic-attributes/

Regards,

Vikas

LeonrdoLemos
Explorer
0 Likes
Any solution? I have the same problem
former_member190293
Active Contributor
0 Likes

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.