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

 

/wp-content/uploads/2014/05/clipboard1_453680.png

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.

/wp-content/uploads/2014/05/clipboard2_453681.png

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

/wp-content/uploads/2014/05/clipboard3_453682.png

 

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

/wp-content/uploads/2014/05/clipboard4_453683.png

3. Create a new word template.

Work center “Service Operation”,

/wp-content/uploads/2014/05/clipboard5_453684.png

 

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

/wp-content/uploads/2014/05/clipboard6_453685.png

click Open in new popup:

/wp-content/uploads/2014/05/clipboard7_453686.png

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.

/wp-content/uploads/2014/05/clipboard8_453687.png

 

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.

 

/wp-content/uploads/2014/05/clipboard9_453688.png

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

/wp-content/uploads/2014/05/clipboard10_453689.png

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

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

/wp-content/uploads/2014/05/clipboard11_453690.png

in popup choose the template created in previous step:

/wp-content/uploads/2014/05/clipboard12_453691.png

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

/wp-content/uploads/2014/05/clipboard13_453695.png

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

/wp-content/uploads/2014/05/clipboard14_453696.png

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.

/wp-content/uploads/2014/05/clipboard15_453697.png

 

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

/wp-content/uploads/2014/05/clipboard16_453698.png

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

/wp-content/uploads/2014/05/clipboard17_453700.png

we can view its content via tcode STRANS:

/wp-content/uploads/2014/05/clipboard18_453701.png

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:

/wp-content/uploads/2014/05/clipboard19_453702.png

 

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:

/wp-content/uploads/2014/05/clipboard20_453703.png

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

/wp-content/uploads/2014/05/clipboard21_453704.png

/wp-content/uploads/2014/05/clipboard22_453705.png

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:

/wp-content/uploads/2014/05/clipboarda1_454139.png

 

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

/wp-content/uploads/2014/05/clipboarda2_454140.png

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.

/wp-content/uploads/2014/05/clipboarda3_454141.png

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.

/wp-content/uploads/2014/05/clipboarda4_454142.png

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

  • consulting note 2023246 – Table not showing correct data in attachment created with template
  • consulting note 2047113 – How to check whether a field in word template is filled correctly by web service
  • consulting note 2047259 – Trouble shooting guide about word document merge with web service
  • consulting note 2048272 – A simulation tool to check document template merge issue
  • 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 .
To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

  1. Snehasish Das

    Hi Jerry,

    This is a Super blog on creating word document template using webservice.

    I followed your steps and in Step 2 after installing SAP Data panel i am not able to see SAP data panel as active add on in word document .Do i need to do anything else.

    Thanks

    Snehasish

    (0) 
  2. Fred Braun

    Hi Jerry

    Thanks for the good explanation. I have a question we would like to convert the Word document afterwards into a PDF and have it attached to the transaction in PDF format. Is it possible to convert the Word document into a PDF directly in CRM?

    I know that it is possible to create immediately a PDF attachment but our users need to edit the attachment before attaching.

    Thanks in advance for your help.

    Fred

    (0) 

Leave a Reply