- 1. Create two new extension fields in Service contract header
- 2. Create a new web service using web service tool
- 3. create BAdI implementation based on enhancement spot CRM_WST_RT_ENHANCEMENT
- 4. Test in UI
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.
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.
2. Create a new web service using web service tool
Make sure you have included the two extension fields into your web service structure.
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.
3. create BAdI implementation based on enhancement spot CRM_WST_RT_ENHANCEMENT
Create a filter for your BAdI implementation whose value equals to the name of web service you created in step2.
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.
And in the runtime, the two extension fields in the template are merged with the data we fill in our BAdI implementation.
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.