Quantcast
Channel: SCN : All Content - All Communities
Viewing all articles
Browse latest Browse all 8392

Create word attachment which consumes external web service

$
0
0


In these two documents below, I have demonstrated the steps how to create word or pdf document as attachments which could consume web service created via CRM web service tool.


Create Webservice enabled Adobe PDF attachment in CRM Application

Create Webservice enabled word document in attachment assignment block


As we could find in document template creation UI, there is a third option which allows us to assign a WSDL URL of an external webservice to a document template. So this document will explain how to create a word template which could consume your own web service, instead of the one created via CRM web service tool.

clipboard1.png


Ensure you have a working web service

 

for simplicity I just create a simple function module which do the add operation and expose it into web service with tcode SOAMANAGER.

clipboard2.png

In order to consume it, An ABAP proxy is needed.

 

Test the ABAP consumer proxy in ABAP workbench and make it work, since it will be used later:

clipboard3.png

clipboard4.png

You could use this document as reference about how to expose a function module into web service via SOAMANAGER and the necessary configuration to consume it in ABAP.


Create word template and assign your webservice WSDL to it


In document creation UI, choose radio box "Own WSDL URL", paste your web service WSDL URL to input field and press entry key, then your web service operation will appear in dropdown list automatically. Choose your operation and click button "Start Designer".

 

If you meet with 401 unauthorization error message after enter key is pressed, refer to this document about solution:

 

How to resolve Unauthorized error message when defining external web service for document template

clipboard5.png

Now a new word document is opened. You could drag the output variable EV_RESULT from SAP Data panel to your word body area.

Its content will be filled by your web service in the runtime. Finish the template development.

clipboard6.png

Implement BAdI to consume the web service

 

Create a BAdI implementation via the customizing activity below:

clipboard7.png

You could refer to my implementation code below:

 

 

DATA: lo_proxy            TYPE REF TO co_zweb_add_21,

            ls_input            TYPE zweb_add_operation,

            ls_output           TYPE zweb_add_operationresponse,

            lo_payload_protocol TYPE REF TO if_wsprotocol_payload,

            lo_payload          TYPE REF TO if_ws_payload,

            lo_payload_handler  TYPE REF TO if_ws_payload_handler,

            lt_request_data     TYPE prx_t_param,

            ls_request_data     TYPE prx_s_param,

            lv_valid_from       TYPE comt_valid_from.

 

 

 

line 17: Create an instance of ABAP consumer proxy class.

 

line 21: The current business object instance GUID is included in importing parameter IS_OBJECT-INSTID.

Since my word template is created based on BOR type BUS1178, so I could directly query product database table COMM_PRODUCT to

find the corresponding product record.

 

line 24 ~ 27: I just fetch the valid from timestamp of current product and pass the date value to the first importing parameter of web service call. The second importing parameter is assigned with 0, so in the final word document we will see the valid from date of current product.

 

line 28: execute web service call, the result is included in parameter ls_output.

 

line 38 and 39: pass out the web service response payload to changing parameter, which will be used by Office integration framework to merge with word template.

clipboard8.png

Test in UI

 

Now you could create attachment based on your word template by clicking button "With Template". Choose the word template you have just developed from pop up window:

clipboard9.png

you could still set breakpoint in your BAdI implementation and the function module exposed as web service to observe how they are consumed in the runtime:

clipboard10.png

clipboard11.png

Finally the web service calculation result is displayed in the word document.

clipboard12.png

Further reading


If you would like to know how a word template is merged with data from xml file, you can find technical detail in this document Understand how the word template is merged with xml data stream .


Viewing all articles
Browse latest Browse all 8392

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>