SAP CRM如何创建支持Web Service的PDF模板

In CRM webclient UI there is a reuse assignment block “Attachment” which are available for most of CRM application.

SAP CRM如何创建支持Web Service的PDF模板_第1张图片

There is a button “With Template” which allows you to create word document whose content will automatically be filled by the web service created by you via web service tool in CRM. This document explains how to archive this step by step and illustrate the technical detail behind it.

This feature is especially useful if you need to fulfill the scenario to create lots of documents for business transaction like Sales order and the document content consists of both static text and dynamic values like Order ID, Order description etc. Then you just need to create a single document template with all static text, and those dynamic values could be filled by web service in the runtime.

In this document I will create such word document for Product as example. The logic is exactly the same if you could like to create web service enabled document for others such as Sales Order, Service order, Opportunities etc.

(1) Create your own web service which will be consumed by your word document.
As Arjun Pawar has already written an excellent document All about Web services – Web Service Tool, I will not repeat the detailed creation steps, but just include the productive web service I created:

There are some important attributes which we can write down for later usage:
a. I specify BOR type BUS1178 for my web service
b. The Genil component PROD is assigned to my web service together with its root node “Product”
c. I have only enabled “Read” operation for my web service
d. There is one function group automatically generated: /CRMOST/JERRY_PROD_WS_FCT. We will discuss it later.

SAP CRM如何创建支持Web Service的PDF模板_第2张图片

(2) Download the word plugin “SAP Data Panel” from service market place. This wiki could guide you how to download and install in your computer.
If you encounter any problems, feel free to contact me.

After successful installation, create a new word document and you will see a new menu “SAP”:

SAP CRM如何创建支持Web Service的PDF模板_第3张图片

It should appear in Active Application Add-ins in your Word option.

SAP CRM如何创建支持Web Service的PDF模板_第4张图片

(3) Create a new word template.
Work center “Service Operation”,

SAP CRM如何创建支持Web Service的PDF模板_第5张图片

Fill all mandatory fields like below and click “Start Designer” button:

SAP CRM如何创建支持Web Service的PDF模板_第6张图片

click Open in new popup:

SAP CRM如何创建支持Web Service的PDF模板_第7张图片

Then a new empty word document is opened. In the right part, the “SAP Data Panel” Addin will display all fields available in root node Product of Genil component PROD as a tree, the root node is named “JerryProdWs”, which is just the web service we created in step1.
Now you can edit this word template by adding the static part like header, footer, field label. Just select the field in the SAP Data Panel, drag it into the left part and drop.

SAP CRM如何创建支持Web Service的PDF模板_第8张图片

This is the final version of my word document. If you put the mouse over the dynamic fields which are dragged from SAP Data Panel, it will be marked with a grey rectangle as a hint that it is dynamic.

SAP CRM如何创建支持Web Service的PDF模板_第9张图片

Once click, the technical name will be displayed on top of it.

SAP CRM如何创建支持Web Service的PDF模板_第10张图片

Now since I already finish the template edit, I could directly close the word application.

(4) Go to Product application, click “With Template” button:

SAP CRM如何创建支持Web Service的PDF模板_第11张图片

in popup choose the template created in previous step:

SAP CRM如何创建支持Web Service的PDF模板_第12张图片

Then the word application is automatically launched with all dynamic data filled as expected:

SAP CRM如何创建支持Web Service的PDF模板_第13张图片

Close the word application and then this document will be saved and appear in the attachment assignment block:

SAP CRM如何创建支持Web Service的PDF模板_第14张图片

Automatically generated Artifacts after web service creation

In step1 after web service creation we write down the function group name /CRMOST/JERRY_PROD_WS_FCT.

In fact there are other artifacts automatically generated by system which are necessary for web service runtime processing:
You will find the function group in package $WS_BOL_GEN ( all function group for other web service are also put here )
Since I have only enabled Read Operation during web service creation step, so within this generated function group there is only one generated function module which will delegate the web service call to the method GET_OBJECTS of Genil implementation class CL_CRM_PRODIL of genil component PROD.

SAP CRM如何创建支持Web Service的PDF模板_第15张图片

also the generated DDIC structure for web service input & output parameter:

SAP CRM如何创建支持Web Service的PDF模板_第16张图片

Query table VEPFUNCST with VEPNAME = my web service name, I can find one generated simple transformation:

SAP CRM如何创建支持Web Service的PDF模板_第17张图片

we can view its content via tcode STRANS:

SAP CRM如何创建支持Web Service的PDF模板_第18张图片

How to debug the web service call

In case your word document content is not correctly filled by web service, you have to configure out whether it is caused by any issue of the web service provider implementation itself ( in my example it is CL_CRM_PRODIL method GET_OBJECTS ) , or there is another possiblity that the data is correctly returned by the service provider, but lost or conrupt during web service framework processing for example output parameter mapping. You can debug to find the root cause.

The entry point is the Office integration handler class CL_OI_HANDLER to handle with the http request:

SAP CRM如何创建支持Web Service的PDF模板_第19张图片

You can set breakpoint on the generated read function module to check whether the call is successfully delegated to the service provider – Genil component implementation class’ GET_OBJECTS method:

SAP CRM如何创建支持Web Service的PDF模板_第20张图片

Then check whether the response returned by service provider is correctly processed by framework via transformation:

SAP CRM如何创建支持Web Service的PDF模板_第21张图片
SAP CRM如何创建支持Web Service的PDF模板_第22张图片

Enhance the value assignment via BAdI Implementation

Sometimes the standard processing of Web service framework might not work exactly as what you expect. Take product application for example,
Suppose you drag the field UPNAME into word document, and through debugging you can confirm that its content is correctly returned by Genil implementation class, but discarded by framework in method clear_attributes in line 49:

SAP CRM如何创建支持Web Service的PDF模板_第23张图片

Since the Product application marks field UPNAME as HIDDEN field, so it will be cleared in the final web service output structure:

SAP CRM如何创建支持Web Service的PDF模板_第24张图片

However if your business scenario does need all hidden fields to be also filled, you can create a BAdI implementation based on enhancement spot CRM_WST_RT_ENHANCEMENT. Specify your web service name as Filter value for SERVICE_NAME.

SAP CRM如何创建支持Web Service的PDF模板_第25张图片

The BAdI implementation is called AFTER framework processing, so now you have the chance to fill any empty fields all by yourself, since all relevant context are available in changing parameter OUTBOUND.

SAP CRM如何创建支持Web Service的PDF模板_第26张图片

For a detailed step by step how to do this, please read this document How to enhance a web service response structure in word template integration.

Create the attachment as PDF format

see this document for detail.

Further reference

(1) consulting note 2023246 – Table not showing correct data in attachment created with template

(2) consulting note 2047113 – How to check whether a field in word template is filled correctly by web service

(3) consulting note 2047259 – Trouble shooting guide about word document merge with web service

(4) consulting note 2048272 – A simulation tool to check document template merge issue

(5) consulting note 2055197 – 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.

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

你可能感兴趣的:(Jerry,Wang的原创SAP技术文章,CRM,ABAP)