Wednesday, August 31, 2011

Navigation and Pop up on CRM WEB UI


Below example is only for CRM Web UI.

In SAP CRM 7, when a document is being created with reference to another document, there might be a requirement to check whether there is already a document which was already created with reference to that document. (For example if you want to create a Complaint on CRM with reference to an ECC Invoice document, and we want to check if there is already a Complaint created against that Invoice. Below is an example in the screenshot where we need to create a Complaint after an invoice is selected. We need to now check if a Complaint already exists for this invoice and then trigger a pop up and then navigate based on the selections made by the user in the pop up.)


I know it’s not a complex requirement. But still I thought of posting here as I enjoyed doing it and maybe it can be useful to someone.

My approach to the requirement is as follows
1. Create a pop up if a document already exists.
2. Pop up has two options called ‘yes’ and ‘no’.
3. If user clicks on ‘yes’ button, it should continue creating a new document which is continuation of the normal process.
4. If user clicks on ‘no’ button, it should navigate to the existing Complaint document that was already created with reference to that invoice.

How to create a pop up and handle it

We first need to identify where to start the process of creating the pop up. For that first we need to identify the component, the view and the method of the controller class where the popup needs to be raised. In my case, I needed to trigger it in the method that got raised after user clicks on the create Complaint button.

To trigger pop up using the controller class, we need to add an attribute to the controller class. Below is attribute details.

CONFIRM_POPUP Instance Type Ref To IF_BSP_WD_POPUP.

In the Complaint create method; I checked if a Complaint already exists for the selected Invoice document. If there was a Complaint already, I called the method EH_ONCONFIRM_POPUP () to raise a pop up. Below is the extract of the code in that method.

method EH_ONCONFIRM_POPUP.

IF CONFIRM_POPUP IS NOT BOUND.

DATA: LV_SAVE TYPE STRING,
LV_TEXT TYPE STRING.

LV_SAVE = CL_WD_UTILITIES=>GET_OTR_TEXT_BY_ALIAS( 'CRM_UIU_GRM_GAG/SAVE' ). "#EC N
LV_TEXT = CL_WD_UTILITIES=>GET_OTR_TEXT_BY_ALIAS( 'CRM_UIU_GRM_GAG/CONFRIM_SAVE' ).

CALL METHOD COMP_CONTROLLER->WINDOW_MANAGER->CREATE_POPUP_2_CONFIRM
EXPORTING
IV_TITLE = 'EXISTING COMPLAINT'
IV_TEXT = 'A COMPLAINT ALREADY EXISTS FOR THIS INVOICE'
IV_BTNCOMBINATION = IF_BSP_WD_WINDOW_MANAGER=>CO_BTNCOMB_YESNOCANCEL
RECEIVING
RV_RESULT = CONFIRM_POPUP.

CONFIRM_POPUP->SET_ON_CLOSE_EVENT(
IV_EVENT_NAME = 'CONFIRM_POPUP_CLOSED'
IV_VIEW = ME ).

ENDIF.

CONFIRM_POPUP->OPEN( ).

endmethod.

Now the pop up is raised, we need to handle what the user has clicked and then navigate based on the user response. Once user selects any option, we can check the method DO_HANDLE_EVENT in order to trigger the follow up method based on the event ‘CONFIRM_POPUP_CLOSED’. Below is the extract of the code in DO_HANDLE_EVENT method.


From the above screenshot, we can see that EH_ONCONFIRM_POPUP_CLOSED () is called. In this method, we will handle the navigation based on the user selection of ‘yes’ or ‘no’ options.

METHOD EH_ONCONFIRM_POPUP_CLOSED.

DATA: LV_ANSWER TYPE STRING,
LV_SAVE_RESULT TYPE ABAP_BOOL,
LR_APPLICATION TYPE REF TO CL_CRM_BOL_ENTITY,
LR_TX TYPE REF TO IF_BOL_TRANSACTION_CONTEXT,
LR_CUCO TYPE REF TO CL_BT120H_C_CUCOCOMPLAINT_IMPL, "CL_CRMCMP_G_BSPWDCOMPONE0_IMPL,
LR_CUCO_WRP TYPE REF TO CL_BSP_WD_COLLECTION_WRAPPER,
LR_ENTITY TYPE REF TO CL_CRM_BOL_ENTITY,
LR_CUWRP TYPE REF TO CL_BSP_WD_COLLECTION_WRAPPER,
LR_WDW TYPE REF TO CL_BSP_WD_WINDOW,
LV_GUID TYPE CRMT_GENIL_OBJECT_GUID,
LR_CORE TYPE REF TO CL_CRM_BOL_CORE,
LR_COLLECTION TYPE REF TO IF_BOL_BO_COL."CL_CRM_BOL_BO_COL.

INCLUDE: CRM_OBJECT_TYPES_CON.

LV_GUID = 'E0752CF1A89EFAF1AE30005056B31BED'.

LV_ANSWER = CONFIRM_POPUP->GET_FIRED_OUTBOUND_PLUG( ).

CASE LV_ANSWER.

WHEN CL_GS_PTC_BSPWDCOMPONENT_CN01=>CO_EVENT_YES.
*Here we can call the method to continue normal creation of the document (Complaint)
CALL METHOD ME->EH_ONCREATECOMPLAINT
EXPORTING
HTMLB_EVENT = HTMLB_EVENT
HTMLB_EVENT_EX = HTMLB_EVENT_EX.

WHEN CL_GS_PTC_BSPWDCOMPONENT_CN01=>CO_EVENT_NO.
*Now we need to navigate to the existing Complaint

LR_CORE = CL_CRM_BOL_CORE=>GET_INSTANCE( ).
LR_ENTITY = LR_CORE->GET_ROOT_ENTITY( IV_OBJECT_NAME = 'BTOrder' IV_OBJECT_GUID = LV_GUID ).
CHECK LR_ENTITY IS BOUND.

CREATE OBJECT LR_COLLECTION TYPE CL_CRM_BOL_BO_COL.
LR_COLLECTION->ADD( LR_ENTITY ).
OP_OVERVIEW( IV_DATA_COLLECTION = LR_COLLECTION ).

WHEN OTHERS.

ENDCASE.


ENDMETHOD.

From the above method we can get the value of what the user has selected using ‘LV_ANSWER’. If the option selected by user is ‘Yes’, we should allow the user to create a new document by following the normal process of creation of the document. If the option selected by user is ‘no’, then the user should automatically navigate to the existing Complaint which was already created which reference to that invoice document.

Automatic navigation to the existing Document (Complaint)

To navigate to the existing complaint document, we need to do the following things.
1. Create an outbound plug on the component that we are working on.
2. Create a navigational link between the outbound plug of your current component and the inbound plug of the component where you want to navigate.

To create an outbound plug, navigate to the component workbench and then you can create an outbound plug. For example I created the outbound plug called ‘OP_OVERVIEW’ so that we can navigate to the main page of the existing document. Below is the extract of the code in the outbound plug method ‘OP_OVERVIEW’.


To create a navigational link, we need to go to runtime repository editor in the component workbench and click on create navigational link. Below is the screenshot of the navigation link that is similar to which we need to create according to our individual requirement.


We need to understand how to use the outbound plug. If we just go back to our method EH_ONCONFIRM_POPUP_CLOSED, we can see the code where an entity (LR_ENTITY) is created using the guid number. Then this entity needs to be added to the collection and then passed onto the outbound plug method.

That's it. Now we know how to create a pop up in web ui, how to handle it and then how to navigate to any page view on web ui.

Hari

4 comments:

  1. Hi,

    I'm new to SAP CRM as well and I'm trying to get my head around the new concepts.
    I received an error message, because I used the same "concept" code.
    What I'm trying to achieve is a popup screen for "user + password" input. I tried this easy example but it seems it's not so easy.
    Now, u're talking about a "view controller" class.
    At the moment I'm using the new created class ZCL_IM_ORDER_SAVE to do some things after save, but in the same time I need this popup.

    In what view do I need to find this controller ?
    Here are the only data that I can think of that can help you share the relevant info
    http://i1327.photobucket.com/albums/u662/nepriceputu/prop1.jpg
    http://i1327.photobucket.com/albums/u662/nepriceputu/prop2.jpg


    Do I access that view with "BSP_WD_CMPWB"?

    Thank you in advance,
    Marius

    ReplyDelete
  2. "Are you need Server access for SAP All modules Contact now and know the Unbelievable offers on Server Access for SAP All modules.
    Grab the Special Offers and Discounts. One time payment available it gets more benefits.
    Visit Us: www.visionsap.com
    Phone No's Calling: +16032623609, Whatsapp: +91 7382121738
    Mail ID: info@visionsap.com
    #SAPoffers #SAPServerOffers #Specialoffers #Specialdiscounts #Limitedoffer #Hurryup
    "

    ReplyDelete
  3. Hi Vision SAP,

    I need the Server Access SAP Sybase HADR, how much price you mentioned above Unbelievable offers on Server Access for SAP All modules. Please update here..

    ReplyDelete