关于sap:SAP-CRM如何创建支持Web-Service的WORD模板

42次阅读

共计 5889 个字符,预计需要花费 15 分钟才能阅读完成。

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

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.

(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”:

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

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

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

click Open in new popup:

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.

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.

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

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

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

in popup choose the template created in previous step:

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

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

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.

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

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

we can view its content via tcode STRANS:

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:

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:

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


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:

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

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.

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.

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 的原创文章,请关注公众号 ” 汪子熙 ”:

正文完
 0