Skip to Content
Author's profile photo Jerry Wang

How to enhance a web service response structure in word template integration

In one of my document Create Webservice enabled word document in attachment assignment block we have discussed how to create a web service based on a BOL model via CRM web service tool. Recently one customer asked me for help that they would like to have more fields like current user and current system date to be displayed in the word document, however those fields are not existing on BOL model. I am asked to provide them a solution to enhance the web service response structure.

The original solution in document Web-services enhancement for MS Word integration in CRM 2007 is no longer valid now, since the automatically generated web service response structure is now marked by SAP as “cannot be enhanced”, to avoid inconsistency caused by any manual change.

/wp-content/uploads/2014/08/clipboard1_511040.png

For example, if we need to create current user and current system date on the word template for Service contract.

1. Create two new extension fields in Service contract header

For detail step by step how to do this using application extension tool, you can refer to this link.

You do not need to configure them in the end UI.

/wp-content/uploads/2014/08/clipboard2_511041.png

2. Create a new web service using web service tool

Make sure you have included the two extension fields into your web service structure.

/wp-content/uploads/2014/08/clipboard3_511042.png

Then create a word template based on this web service. And then the two extension fields are available in the web service response structure. You could now use them in the word template.

/wp-content/uploads/2014/08/clipboard4_511043.png

3. create BAdI implementation based on enhancement spot CRM_WST_RT_ENHANCEMENT

/wp-content/uploads/2014/08/clipboard5_511044.png

Create a filter for your BAdI implementation whose value equals to the name of web service you created in step2.

/wp-content/uploads/2014/08/clipboard6_511045.png

Implement method as below:

 

METHOD if_ex_crm_wst_rt_badi~outbound_processing.

FIELD-SYMBOLS: <container> TYPE any,
<root>      TYPE any,
<header>    TYPE any,
<user>      TYPE any,
<date>      TYPE any.

ASSIGN outbound->* TO <container>.

* replace ZSERV_CONTRACT with your own web service name
ASSIGN COMPONENT 'ZSERV_CONTRACT' OF STRUCTURE <container> TO <root>.
CHECK sy-subrc = 0.

ASSIGN COMPONENT 'ADMINISTRATIVEHEADEROFORDER' OF STRUCTURE <root> TO <header>.
CHECK sy-subrc = 0.

ASSIGN COMPONENT 'ZZFLD00012H' OF STRUCTURE <header> TO <user>.
CHECK sy-subrc = 0.

<user> = sy-uname.

ASSIGN COMPONENT 'ZZFLD00012I' OF STRUCTURE <header> TO <user>.
CHECK sy-subrc = 0.

<user> = sy-datlo.

ENDMETHOD.​

4. Test in UI

Create a new attachment for a given Service contract based on the word template you created in step2.

/wp-content/uploads/2014/08/clipboard7_511046.png

And in the runtime, the two extension fields in the template are merged with the data we fill in our BAdI implementation.

/wp-content/uploads/2014/08/clipboard8_511047.png

Conclusion

Using AET to enhance the web service structure and BAdI implementation to fill extension fields with values, we could fulfill customer requirement with a modification free approach. Such enhancement is transportable and could still survive after upgrade.

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.