CRM Web Channel – FM Listener
In CRM Web Channel, there are several enhancement concept. One of the most tricky one is function module listener. Using function module listener concept, you can intercept function calls to the SAP system. A Java listener can be registered and is notified before and after calling a function module. You can use this listener to manipulate input/output parameters. You also have access to the Backend Context.
This is an example to show how to use function module listener.
Step 1. Create listener class.
Listener class must implement interface ‘com.sap.isa.core.eai.sp.jco.JCoConnectionEventListener‘.
/* * Created on 2009-10-23 * * To change the template for this generated file go to * Window>;Preferences>;Java>;Code Generation>;Code and Comments */ package com.yourcompany.isa.event; import com.honeywell.isa.businessobject.bobpricing.Z_BobPricingConstants; import com.sap.isa.businessobject.Shop; import com.sap.isa.core.eai.sp.jco.JCoConnectionEvent; import com.sap.isa.core.eai.sp.jco.JCoConnectionEventListener; import com.sap.mw.jco.JCO; /** * @author Andy * * This class will be called when calling the function module 'CRM_ISA_BASKET_GETTEXT'. * This function module will use the same text id for both header and item text, so we need to copy this * function module out to add some more logic. */ public class Z_TextGetEventListener implements JCoConnectionEventListener { /* (non-Javadoc) * @see com.sap.isa.core.eai.sp.jco.JCoConnectionEventListener#connectionEvent(com.sap.isa.core.eai.sp.jco.JCoConnectionEvent) */ public void connectionEvent(JCoConnectionEvent event) { if(event.getId() == JCoConnectionEvent.BEFORE_JCO_FUNCTION_CALL){ //check whether the item text id is maintained in the shop administrator Shop shop = (Shop)event.getBackendContext().getAttribute(Z_BobPricingConstants.SHOP); if(shop == null){ return; } String itemTextId = (String)shop.getExtensionData("ZZ_ITEM_TDID"); String headerTextId = (String)shop.getExtensionData("ZZ_HEADER_TDID"); if(itemTextId == null || itemTextId.equals("")){ return; } if(headerTextId == null || headerTextId.equals("")){ return; } JCO.Function function = event.getJCoFunction(); JCO.Table textTable = function.getTableParameterList().getTable("TEXT_LINE"); //append a new line for the seperate header and item text id textTable.appendRow(); textTable.setValue((headerTextId + "||" + itemTextId) , "TDLINE"); } else{ return; } } }
Step 2. Register the class into file ‘modification-config.xml’.
<function-module-listener>
<param name=”fmevent:CRM_ISA_BASKET_GETTEXT” value=”com.honeywell.isa.event.Z_TextGetEventListener”/>
</function-module-listener>