Advertising:

Create your own Fiori push notifications: Difference between revisions

From SAP Knowledge Base
Line 219: Line 219:


Perse the provider is not activated, which is why you still have to activate it.
Perse the provider is not activated, which is why you still have to activate it.
Translated with DeepL.com (free version)

Revision as of 10:20, 24 December 2024

There is a “bell” icon in the Fiori Launchpad. All Fiori push notifications are displayed here. The aim of this wiki article is to enable you to display your own notifications there. The prerequisite is that the technical setup and configuration has been carried out in the system.

Overview of the required objects and customizing

  • Creation of Y/Z notification class
    • Interface /iwngw/if_notif_provider
    • Implementation method /iwngw/if_notif_provider~get_notification_parameters
    • Implementation method /iwngw/if_notif_provider~get_notification_type
    • Implementation method /iwngw/if_notif_provider~get_notification_type_text
    • Implementation method /iwngw/if_notif_provider~handle_action
    • Implementation method send_notification
  • Customizing
    • Register notification provider
    • Manage notification provider

Creation of Y/Z Notification class

For method send_notification you have to consider which parameters are required. Also the success/error handling.

Example Code

 CLASS ycl_your_class_notifprov DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.
    INTERFACES /iwngw/if_notif_provider .

    CONSTANTS notification_provider_id TYPE /iwngw/notif_provider_id  VALUE 'YMODULE_NOTIF_PROV_ID' ##NO_TEXT.

    CONSTANTS:
      BEGIN OF notification_type,
        general_gr                 TYPE /iwngw/notification_type_key VALUE 'GenGrForAPoItem',
        gr_with_ref_to_sales_order TYPE /iwngw/notification_type_key VALUE 'SalesOrderGrForAPoItem',
      END OF notification_type.

    CLASS-METHODS: send_notification
                    IMPORTING purchaseorder TYPE I_PurchaseOrderAPI01-PurchaseOrder
                    EXPORTING is_sending_successful TYPE abap_bool
                              ex_msg TYPE string.
  PROTECTED SECTION.
  PRIVATE SECTION.
   CLASS-DATA: parameters type /iwngw/if_notif_provider=>ty_t_notification_parameter.
 ENDCLASS.
 
 CLASS ycl_your_class_notifprov IMPLEMENTATION.
  METHOD /iwngw/if_notif_provider~get_notification_parameters ##NEEDED.
   CLEAR: parameter.
   
    SET LANGUAGE language.

    LOOP AT parameters ASSIGNING FIELD-SYMBOL(<para>).
     MOVE-CORRESPONDING <para> TO parameter.
    ENDLOOP.
    SET LANGUAGE lang.
  ENDMETHOD.

  METHOD /iwngw/if_notif_provider~get_notification_type.
    DATA notif_action LIKE LINE OF notification_action ##NEEDED.

    CLEAR notification_type.
    CLEAR notification_action.

    CASE type_key.
      WHEN notification_type-general_gr.
        notification_type-type_key     = notification_type-general_gr.
        notification_type-version      = 0.
        notification_type-is_groupable = abap_true.
      WHEN notification_type-gr_with_ref_to_sales_order.
        notification_type-type_key     = notification_type-gr_with_ref_to_sales_order.
        notification_type-version      = 0.
        notification_type-is_groupable = abap_true.
      WHEN OTHERS.
        RAISE EXCEPTION TYPE /iwngw/cx_notif_provider.
    ENDCASE.
  ENDMETHOD.

   METHOD /iwngw/if_notif_provider~get_notification_type_text.
    DATA tmp_text TYPE string.

    CLEAR type_text.
    CLEAR action_text.

    SET LANGUAGE language.

    CASE type_key.
      WHEN notification_type-general_gr.
        tmp_text = TEXT-100.
        REPLACE '&1' WITH '{po}' INTO tmp_text.
        REPLACE '&2' WITH '{poitem}' INTO tmp_text.
        type_text-template_public    = tmp_text.
        type_text-template_grouped   = TEXT-101.
        CLEAR lv_tmp_text.
        tmp_text = TEXT-102.
        REPLACE '&1' WITH '{article}' INTO tmp_text.
        REPLACE '&2' WITH '{plant}' INTO tmp_text.
        type_text-subtitle           = tmp_text.
        type_text-description        = TEXT-103.
      WHEN mc_notification_type-gr_with_ref_to_sales_order.
        tmp_text = TEXT-200.
        REPLACE '&1' WITH '{po}' INTO tmp_text.
        REPLACE '&2' WITH '{poitem}' INTO tmp_text.
        REPLACE '&3' WITH '{so}' INTO tmp_text.
        type_text-template_public    = tmp_text.
        type_text-template_grouped   = TEXT-201.
        CLEAR tmp_text.
        tmp_text = TEXT-202.
        REPLACE '&1' WITH '{article}' INTO tmp_text.
        REPLACE '&2' WITH '{plant}' INTO tmp_text.
        type_text-subtitle           = tmp_text.
        type_text-description        = TEXT-203.
      WHEN OTHERS.
        RAISE EXCEPTION TYPE /iwngw/cx_notif_provider.
    ENDCASE.

  ENDMETHOD.

 METHOD /iwngw/if_notif_provider~handle_action.
    CLEAR result.

*   For now always return success if ids are set, since no persistence in this provider
    IF notification_id IS INITIAL.
      result-success = abap_false.
    ELSEIF action_key IS INITIAL.
      result-success = abap_false.
    ELSE.
      result-success          = abap_true.
      result-delete_on_return = abap_true.
    ENDIF.
 ENDMETHOD.
 
   METHOD /iwngw/if_notif_provider~handle_bulk_action.
*   no bulk notifications supported
    CLEAR notif_result.
  ENDMETHOD.
  
 METHOD send_notification.

   CLEAR parameters.

    TRY.

     DATA: recipients type /iwngw/if_notif_provider=>ty_t_notification_recipient,
           parameters type /iwngw/if_notif_provider=>ty_t_notification_parameter,
           type_key type /iwngw/notification_type_key.

     IF salesorder_creator IS INITIAL.
      recipients = VALUE #( ( id = purchaseorder_creator ) ).
      parameters = VALUE #(  ( name = 'po' value = purchaseorder type = 'Edm.String' is_sensitive = abap_false )
                             ( name = 'poitem' value = poitem type = 'Edm.String' is_sensitive = abap_false )
                             ( name = 'article' value = product type = 'Edm.String' is_sensitive = abap_false )
                             ( name = 'plant' value = plant type = 'Edm.String' is_sensitive = abap_false ) ).
      type_key = notification_type-general_gr.
     ELSE.
      recipients = VALUE #( ( id = purchaseorder_creator ) ( id = salesorder_creator ) ).
      parameters = VALUE #( ( name = 'po' value = purchaseorder type = 'Edm.String' is_sensitive = abap_false )
                            ( name = 'poitem' value = poitem type = 'Edm.String' is_sensitive = abap_false )
                            ( name = 'so' value = salesorder type = 'Edm.String' is_sensitive = abap_false )
                            ( name = 'article' value = product type = 'Edm.String' is_sensitive = abap_false )
                            ( name = 'plant' value = plant type = 'Edm.String' is_sensitive = abap_false ) ).
      type_key = notification_type-gr_with_ref_to_sales_order.
     ENDIF.

     /iwngw/cl_notification_api=>create_notifications(
                EXPORTING
                  iv_provider_id  = notification_provider_id
                  it_notification = VALUE #( ( id = cl_uuid_factory=>create_system_uuid( )->create_uuid_x16( )
                                             type_key = lv_type_key
                                             type_version = '0'
                                             priority = 'NEUTRAL'
                                             navigation_parameters = VALUE #( ( name = 'MaterialDocument' value = matdoc )
                                                                              ( name = 'MaterialDocumentYear' value = matdoc_year )
                                                                              ( name = 'sap-fiori-id' value = 'F1077' )
                                                                              ( name = 'StockCHangeContext' value = '' )
                                                                              ( name = 'StockCHangeContext' value = '01' )
                                                                              ( name = 'StockChangeType' value = '05')
                                                                              ( name = 'sap-keep-alive' value = 'restricted' )
                                                                              ( name = 'MaterialDocumentItem' value = matdoc_item ) )
                                             navigation_target_object = 'MaterialDocument'
                                             navigation_target_action = 'displayFactSheet'
                                             recipients = recipients
                                             parameters = VALUE #( language = sy-datum
                                                                 ( parameters = parameters ) ) ) ) ).
      CATCH cx_uuid_error INTO DATA(rx_uuid_error).
       ex_msg = lrx_uuid_error->get_text( ).
       RETURN.
      CATCH /iwngw/cx_notification_api INTO DATA(rx_api).
        " HANDLE ERROR
       ex_msg = rx_api->get_text( ).
       RETURN.
    ENDTRY.
    is_sending_successful = abap_true.
  ENDMETHOD.

 ENDCLASS.

Necessary customizing

Register notification provider

Use the “Register provider” button to register the notification provider. A name for the provider, e.g. “YMM_...” and the created provider class are assigned here.

Note'
The created entries are created in the respective logged-in system language (time of creation of the wiki article for release 2023). This means that if the customizing entry was made in German, it will not be visible when EN logs in. The language to be used for customizing should be agreed in the project.

Manage notification provider

Perse the provider is not activated, which is why you still have to activate it.


This is a wiki created in the spare time of a private person working in the SAP ERP area. The aim is to collect knowledge for the own use. The wiki is maintained to the best of knowledge and belief.
All products shown, including in form of screenshots, belong to SAP SE. Their trademarks are, among others: SAP®,ABAP®,SAP Fiori®,SAP HANA®,SAP NetWeaver®,SAP® R/3®,SAP S/4HANA®,SAP S/4HANA® Cloud