Partager via


Responding back to SAP from Logic App

So you've registered SAP as a trigger in Azure Logic Apps, enabling SAP to call it as for any other RFC. But how do you parse the SAP request and respond back to it with actual content and not just a vanilla OK?

If you enable the support for multiple RFCs by your Logic App for SAP to call, you need to arrange your logic by Action Uri, that trigger output json parameter which will contain which RFC got call by SAP. For this example we'll just consider a single RFC as a simplification - STFC_CONNECTION. The trigger has been configured for this one only, using the trigger input parameter action URI which causes the SAP Adapter in the On-Premises Data Gateway to act as a filter rejecting calls to other RFCs by SAP. [You can see an example of that in the summary picture at the bottom of this post.]

The next step is to get the XML payload of the SAP RFC call. This is in the trigger output Content parameter @triggerBody()?['Content'], but natively as a string (because Json doesn't have a type for XML). So you want to cast the type to XML with @xml(triggerBody()?['Content']).
Now Logic App knows this is XML as visible in the designer run history view:

To manipulate the XML we can use the X-PATH native support, and here we'll extract the SAP RFC STFC_CONNECTION request text value with @{xpath(xml(triggerBody()?['Content']),'string(/*[local-name()=\"STFC_CONNECTION\"]/*[local-name()=\"REQUTEXT\"])')}

Now we can use this extracted value to form a dynamic response to SAP with @{variables('REQUTEXTValue')}, such as in <STFC_CONNECTIONResponse xmlns=\"https://Microsoft.LobServices.Sap/2007/03/Rfc/\"><ECHOTEXT>@{variables('REQUTEXTValue')}</ECHOTEXT><RESPTEXT>Received</RESPTEXT></STFC_CONNECTIONResponse>

Calling from SAP Logon we can see the dynamic echo response:

For a more complete manipulation of the input request, consider converting the request XML to Json (/en-us/azure/logic-apps/workflow-definition-language-functions-reference#json) or transforming the XML with XSLT (/en-us/azure/logic-apps/logic-apps-enterprise-integration-maps).

Here is the designer view for this whole Logic App:

Comments

  • Anonymous
    April 22, 2019
    A couple notes for people using the xpath example in different context than SAP connector:1. Make sure you have the right expression to get to the XML content. With the SAP connector trigger the XML content is wrapped in Json output of the trigger under the property Content, thus the expression is xml(triggerBody()?['Content']). If you have a trigger like an HTTP trigger which whole payload is XML itself without a Json wrapper, the expression would be more simply xml(triggerBody()) (no ?['Content'])2. The XPATH example I provided only checks for the XML nodes names, not the namespace. You can check namespaces with an AND condition like this (/*[local-name()="NodeName" and namespace-uri()="http://my.name/space"]
  • Anonymous
    June 20, 2019
    This blog has been moved off the MSDN platform. Find further content and update at https://www.linkedin.com/today/author/daviburgComments are locked as part of the blog migration, so please reach out to your customer support contact for assistance with Microsoft products and services.