Advertising:
Create your own Fiori push notifications: Difference between revisions
From SAP Knowledge Base
No edit summary |
|||
(8 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
The prerequisite is that the technical setup and configuration has been carried out in the system. | The prerequisite is that the technical setup and configuration has been carried out in the system. | ||
= Overview of the required objects and customizing = | == Overview of the required objects and customizing == | ||
* Creation of Y/Z notification class | * Creation of Y/Z notification class | ||
Line 18: | Line 18: | ||
** Manage notification provider | ** Manage notification provider | ||
= Creation of Y/Z Notification class = | == Creation of Y/Z Notification class == | ||
For method send_notification you have to consider which parameters are required. Also the success/error handling. | For method send_notification you have to consider which parameters are required. Also the success/error handling. | ||
<div class="toccolours mw-collapsible mw-collapsed"> | |||
Example Code | |||
<div class="mw-collapsible-content"> | |||
<syntaxhighlight lang="abap" line copy> | <syntaxhighlight lang="abap" line copy> | ||
CLASS ycl_your_class_notifprov DEFINITION | CLASS ycl_your_class_notifprov DEFINITION | ||
Line 30: | Line 33: | ||
INTERFACES /iwngw/if_notif_provider . | INTERFACES /iwngw/if_notif_provider . | ||
CONSTANTS | CONSTANTS notification_provider_id TYPE /iwngw/notif_provider_id VALUE 'YMODULE_NOTIF_PROV_ID' ##NO_TEXT. | ||
CONSTANTS: | CONSTANTS: | ||
BEGIN OF | BEGIN OF notification_type, | ||
general_gr TYPE /iwngw/notification_type_key VALUE 'GenGrForAPoItem', | general_gr TYPE /iwngw/notification_type_key VALUE 'GenGrForAPoItem', | ||
gr_with_ref_to_sales_order TYPE /iwngw/notification_type_key VALUE 'SalesOrderGrForAPoItem', | gr_with_ref_to_sales_order TYPE /iwngw/notification_type_key VALUE 'SalesOrderGrForAPoItem', | ||
END OF | END OF notification_type. | ||
CLASS-METHODS: send_notification | CLASS-METHODS: send_notification | ||
IMPORTING | IMPORTING purchaseorder TYPE I_PurchaseOrderAPI01-PurchaseOrder | ||
EXPORTING | EXPORTING is_sending_successful TYPE abap_bool | ||
ex_msg TYPE string. | |||
PROTECTED SECTION. | PROTECTED SECTION. | ||
PRIVATE SECTION. | PRIVATE SECTION. | ||
CLASS-DATA: | CLASS-DATA: parameters type /iwngw/if_notif_provider=>ty_t_notification_parameter. | ||
ENDCLASS. | ENDCLASS. | ||
CLASS ycl_your_class_notifprov IMPLEMENTATION. | CLASS ycl_your_class_notifprov IMPLEMENTATION. | ||
METHOD /iwngw/if_notif_provider~get_notification_parameters ##NEEDED. | METHOD /iwngw/if_notif_provider~get_notification_parameters ##NEEDED. | ||
CLEAR: | CLEAR: parameter. | ||
SET LANGUAGE | SET LANGUAGE language. | ||
LOOP AT | LOOP AT parameters ASSIGNING FIELD-SYMBOL(<para>). | ||
MOVE-CORRESPONDING < | MOVE-CORRESPONDING <para> TO parameter. | ||
ENDLOOP. | ENDLOOP. | ||
SET LANGUAGE | SET LANGUAGE lang. | ||
ENDMETHOD. | ENDMETHOD. | ||
METHOD /iwngw/if_notif_provider~get_notification_type. | METHOD /iwngw/if_notif_provider~get_notification_type. | ||
DATA | DATA notif_action LIKE LINE OF notification_action ##NEEDED. | ||
CLEAR | CLEAR notification_type. | ||
CLEAR | CLEAR notification_action. | ||
CASE | CASE type_key. | ||
WHEN | WHEN notification_type-general_gr. | ||
notification_type-type_key = notification_type-general_gr. | |||
notification_type-version = 0. | |||
notification_type-is_groupable = abap_true. | |||
WHEN | 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. | WHEN OTHERS. | ||
RAISE EXCEPTION TYPE /iwngw/cx_notif_provider. | RAISE EXCEPTION TYPE /iwngw/cx_notif_provider. | ||
Line 80: | Line 83: | ||
METHOD /iwngw/if_notif_provider~get_notification_type_text. | METHOD /iwngw/if_notif_provider~get_notification_type_text. | ||
DATA | DATA tmp_text TYPE string. | ||
CLEAR | CLEAR type_text. | ||
CLEAR | CLEAR action_text. | ||
SET LANGUAGE | SET LANGUAGE language. | ||
CASE | CASE type_key. | ||
WHEN | WHEN notification_type-general_gr. | ||
tmp_text = TEXT-100. | |||
REPLACE '&1' WITH '{po}' INTO | REPLACE '&1' WITH '{po}' INTO tmp_text. | ||
REPLACE '&2' WITH '{poitem}' INTO | REPLACE '&2' WITH '{poitem}' INTO tmp_text. | ||
type_text-template_public = tmp_text. | |||
type_text-template_grouped = TEXT-101. | |||
CLEAR lv_tmp_text. | CLEAR lv_tmp_text. | ||
tmp_text = TEXT-102. | |||
REPLACE '&1' WITH '{article}' INTO | REPLACE '&1' WITH '{article}' INTO tmp_text. | ||
REPLACE '&2' WITH '{plant}' INTO | 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. | WHEN mc_notification_type-gr_with_ref_to_sales_order. | ||
tmp_text = TEXT-200. | |||
REPLACE '&1' WITH '{po}' INTO | REPLACE '&1' WITH '{po}' INTO tmp_text. | ||
REPLACE '&2' WITH '{poitem}' INTO | REPLACE '&2' WITH '{poitem}' INTO tmp_text. | ||
REPLACE '&3' WITH '{so}' INTO | REPLACE '&3' WITH '{so}' INTO tmp_text. | ||
type_text-template_public = tmp_text. | |||
type_text-template_grouped = TEXT-201. | |||
CLEAR | CLEAR tmp_text. | ||
tmp_text = TEXT-202. | |||
REPLACE '&1' WITH '{article}' INTO | REPLACE '&1' WITH '{article}' INTO tmp_text. | ||
REPLACE '&2' WITH '{plant}' INTO | REPLACE '&2' WITH '{plant}' INTO tmp_text. | ||
type_text-subtitle = tmp_text. | |||
type_text-description = TEXT-203. | |||
WHEN OTHERS. | WHEN OTHERS. | ||
RAISE EXCEPTION TYPE /iwngw/cx_notif_provider. | RAISE EXCEPTION TYPE /iwngw/cx_notif_provider. | ||
Line 120: | Line 123: | ||
METHOD /iwngw/if_notif_provider~handle_action. | METHOD /iwngw/if_notif_provider~handle_action. | ||
CLEAR | CLEAR result. | ||
* For now always return success if ids are set, since no persistence in this provider | * For now always return success if ids are set, since no persistence in this provider | ||
IF | IF notification_id IS INITIAL. | ||
result-success = abap_false. | |||
ELSEIF | ELSEIF action_key IS INITIAL. | ||
result-success = abap_false. | |||
ELSE. | ELSE. | ||
result-success = abap_true. | |||
result-delete_on_return = abap_true. | |||
ENDIF. | ENDIF. | ||
ENDMETHOD. | ENDMETHOD. | ||
Line 135: | Line 138: | ||
METHOD /iwngw/if_notif_provider~handle_bulk_action. | METHOD /iwngw/if_notif_provider~handle_bulk_action. | ||
* no bulk notifications supported | * no bulk notifications supported | ||
CLEAR | CLEAR notif_result. | ||
ENDMETHOD. | ENDMETHOD. | ||
METHOD send_notification. | METHOD send_notification. | ||
CLEAR | CLEAR parameters. | ||
TRY. | TRY. | ||
DATA: | 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 | 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. | 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. | ENDIF. | ||
/iwngw/cl_notification_api=>create_notifications( | /iwngw/cl_notification_api=>create_notifications( | ||
EXPORTING | EXPORTING | ||
iv_provider_id = | iv_provider_id = notification_provider_id | ||
it_notification = VALUE #( ( id = cl_uuid_factory=>create_system_uuid( )->create_uuid_x16( ) | it_notification = VALUE #( ( id = cl_uuid_factory=>create_system_uuid( )->create_uuid_x16( ) | ||
type_key = lv_type_key | type_key = lv_type_key | ||
type_version = '0' | type_version = '0' | ||
priority = 'NEUTRAL' | priority = 'NEUTRAL' | ||
navigation_parameters = VALUE #( ( name = 'MaterialDocument' value = | navigation_parameters = VALUE #( ( name = 'MaterialDocument' value = matdoc ) | ||
( name = 'MaterialDocumentYear' value = | ( name = 'MaterialDocumentYear' value = matdoc_year ) | ||
( name = 'sap-fiori-id' value = 'F1077' ) | ( name = 'sap-fiori-id' value = 'F1077' ) | ||
( name = 'StockCHangeContext' value = '' ) | ( name = 'StockCHangeContext' value = '' ) | ||
Line 179: | Line 182: | ||
( name = 'StockChangeType' value = '05') | ( name = 'StockChangeType' value = '05') | ||
( name = 'sap-keep-alive' value = 'restricted' ) | ( name = 'sap-keep-alive' value = 'restricted' ) | ||
( name = 'MaterialDocumentItem' value = | ( name = 'MaterialDocumentItem' value = matdoc_item ) ) | ||
navigation_target_object = 'MaterialDocument' | navigation_target_object = 'MaterialDocument' | ||
navigation_target_action = 'displayFactSheet' | navigation_target_action = 'displayFactSheet' | ||
recipients = | recipients = recipients | ||
parameters = VALUE #( language = sy-datum | parameters = VALUE #( language = sy-datum | ||
( parameters = | ( parameters = parameters ) ) ) ) ). | ||
CATCH cx_uuid_error INTO DATA( | CATCH cx_uuid_error INTO DATA(rx_uuid_error). | ||
ex_msg = lrx_uuid_error->get_text( ). | |||
RETURN. | |||
CATCH /iwngw/cx_notification_api INTO DATA( | CATCH /iwngw/cx_notification_api INTO DATA(rx_api). | ||
" HANDLE ERROR | " HANDLE ERROR | ||
ex_msg = rx_api->get_text( ). | |||
RETURN. | |||
ENDTRY. | ENDTRY. | ||
is_sending_successful = abap_true. | |||
ENDMETHOD. | ENDMETHOD. | ||
ENDCLASS. | ENDCLASS. | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</div> | |||
</div> | |||
= Necessary customizing = | == Necessary customizing == | ||
== Register notification provider == | === Register notification provider === | ||
Use the “Register provider” button to register the notification provider. | Use the “Register provider” button to register the notification provider. | ||
A name for the provider, e.g. “YMM_...” and the | A name for the provider, e.g. “YMM_...” and the created provider class are assigned here. | ||
{| style="border:1px solid black; border-radius: 6px;” | {| style="border:1px solid black; border-radius: 6px;” | ||
| '''Note | | '''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. | | 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 == | === Manage notification provider === | ||
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. | ||
Latest revision as of 11:38, 31 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.