Advertising:
Create your own Fiori push notifications: Difference between revisions
From SAP Knowledge Base
No edit summary |
|||
Line 16: | Line 16: | ||
* Customizing | * Customizing | ||
** Register notification provider | ** Register notification provider | ||
** Manage notification | ** Manage notification provider | ||
= Creation of Y/Z Notification class = | = Creation of Y/Z Notification class = |
Revision as of 19:24, 23 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.
CLASS ycl_your_class_notifprov DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES /iwngw/if_notif_provider .
CONSTANTS mc_notification_provider_id TYPE /iwngw/notif_provider_id VALUE 'YMM_PUR_WE_MSG_PO_ITEM' ##NO_TEXT.
CONSTANTS:
BEGIN OF mc_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 mc_notification_type.
CLASS-METHODS: send_notification
IMPORTING iv_purchaseorder TYPE I_PurchaseOrderAPI01-PurchaseOrder
EXPORTING ev_is_sending_successful TYPE abap_bool
ev_ex_msg TYPE string.
PROTECTED SECTION.
PRIVATE SECTION.
CLASS-DATA: _mt_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:et_parameter.
SET LANGUAGE iv_language.
LOOP AT _mt_parameters ASSIGNING FIELD-SYMBOL(<ls_para>).
MOVE-CORRESPONDING <ls_para> TO et_parameter.
ENDLOOP.
SET LANGUAGE lv_lang.
ENDMETHOD.
METHOD /iwngw/if_notif_provider~get_notification_type.
DATA ls_notif_action LIKE LINE OF et_notification_action ##NEEDED.
CLEAR es_notification_type.
CLEAR et_notification_action.
CASE iv_type_key.
WHEN mc_notification_type-general_gr.
es_notification_type-type_key = mc_notification_type-general_gr.
es_notification_type-version = 0.
es_notification_type-is_groupable = abap_true.
WHEN mc_notification_type-gr_with_ref_to_sales_order.
es_notification_type-type_key = mc_notification_type-gr_with_ref_to_sales_order.
es_notification_type-version = 0.
es_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 lv_tmp_text TYPE string.
CLEAR es_type_text.
CLEAR et_action_text.
SET LANGUAGE iv_language.
CASE iv_type_key.
WHEN mc_notification_type-general_gr.
lv_tmp_text = TEXT-100.
REPLACE '&1' WITH '{po}' INTO lv_tmp_text.
REPLACE '&2' WITH '{poitem}' INTO lv_tmp_text.
es_type_text-template_public = lv_tmp_text.
es_type_text-template_grouped = TEXT-101.
CLEAR lv_tmp_text.
lv_tmp_text = TEXT-102.
REPLACE '&1' WITH '{article}' INTO lv_tmp_text.
REPLACE '&2' WITH '{plant}' INTO lv_tmp_text.
es_type_text-subtitle = lv_tmp_text.
es_type_text-description = TEXT-103.
WHEN mc_notification_type-gr_with_ref_to_sales_order.
lv_tmp_text = TEXT-200.
REPLACE '&1' WITH '{po}' INTO lv_tmp_text.
REPLACE '&2' WITH '{poitem}' INTO lv_tmp_text.
REPLACE '&3' WITH '{so}' INTO lv_tmp_text.
es_type_text-template_public = lv_tmp_text.
es_type_text-template_grouped = TEXT-201.
CLEAR lv_tmp_text.
lv_tmp_text = TEXT-202.
REPLACE '&1' WITH '{article}' INTO lv_tmp_text.
REPLACE '&2' WITH '{plant}' INTO lv_tmp_text.
es_type_text-subtitle = lv_tmp_text.
es_type_text-description = TEXT-203.
WHEN OTHERS.
RAISE EXCEPTION TYPE /iwngw/cx_notif_provider.
ENDCASE.
ENDMETHOD.
METHOD /iwngw/if_notif_provider~handle_action.
CLEAR es_result.
* For now always return success if ids are set, since no persistence in this provider
IF iv_notification_id IS INITIAL.
es_result-success = abap_false.
ELSEIF iv_action_key IS INITIAL.
es_result-success = abap_false.
ELSE.
es_result-success = abap_true.
es_result-delete_on_return = abap_true.
ENDIF.
ENDMETHOD.
METHOD /iwngw/if_notif_provider~handle_bulk_action.
* no bulk notifications supported
CLEAR et_notif_result.
ENDMETHOD.
METHOD send_notification.
CLEAR _mt_parameters.
TRY.
DATA: lt_recipients type /iwngw/if_notif_provider=>ty_t_notification_recipient,
lt_parameters type /iwngw/if_notif_provider=>ty_t_notification_parameter,
lv_type_key type /iwngw/notification_type_key.
IF iv_so_creator IS INITIAL.
lt_recipients = VALUE #( ( id = iv_po_creator ) ).
_mt_parameters = VALUE #( ( name = 'po' value = iv_purchaseorder type = 'Edm.String' is_sensitive = abap_false )
( name = 'poitem' value = iv_poitem type = 'Edm.String' is_sensitive = abap_false )
( name = 'article' value = iv_product type = 'Edm.String' is_sensitive = abap_false )
( name = 'plant' value = iv_plant type = 'Edm.String' is_sensitive = abap_false ) ).
lv_type_key = mc_notification_type-general_gr.
ELSE.
lt_recipients = VALUE #( ( id = iv_po_creator ) ( id = iv_so_creator ) ).
_mt_parameters = VALUE #( ( name = 'po' value = iv_purchaseorder type = 'Edm.String' is_sensitive = abap_false )
( name = 'poitem' value = iv_poitem type = 'Edm.String' is_sensitive = abap_false )
( name = 'so' value = iv_salesorder type = 'Edm.String' is_sensitive = abap_false )
( name = 'article' value = iv_product type = 'Edm.String' is_sensitive = abap_false )
( name = 'plant' value = iv_plant type = 'Edm.String' is_sensitive = abap_false ) ).
lv_type_key = mc_notification_type-gr_with_ref_to_sales_order.
ENDIF.
/iwngw/cl_notification_api=>create_notifications(
EXPORTING
iv_provider_id = mc_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 = iv_matdoc )
( name = 'MaterialDocumentYear' value = iv_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 = iv_matdoc_item ) )
navigation_target_object = 'MaterialDocument'
navigation_target_action = 'displayFactSheet'
recipients = lt_recipients
parameters = VALUE #( language = sy-datum
( parameters = _mt_parameters ) ) ) ) ).
CATCH cx_uuid_error INTO DATA(lrx_uuid_error).
ev_ex_msg = lrx_uuid_error->get_text( ).
RETURN.
CATCH /iwngw/cx_notification_api INTO DATA(lrx_api).
" HANDLE ERROR
ev_ex_msg = lrx_api->get_text( ).
RETURN.
ENDTRY.
ev_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 previously 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.
Translated with DeepL.com (free version)