Skip to Content
Technical Articles

Fiori Push Notification – How to develop Fiori Notifications – Part 3

This blog post is a continuation of my blog series on Fiori Push Notification.

In this blog I will try to detail out how we can create Notification Provider.

To create the notification provider, we have to implement the interface /IWNGW/IF_NOTIF_PROVIDER and use these methods as per our need.

There are four methods provided as a part of interface:

  1. GET_NOTIFICATION_TYPE
  2. GET_NOTIFICATION_TYPE_TEXT
  3. GET_NOTIFICATION_PARAMETERS
  4. HANDLE_ACTION

More details about the significance of these methods are documented here.

To understand the notification provider, we need to understand the very nature of the class and when it is called. The notification provider is a consumer class, which means that it only consumes the notification object and helps us to visualize notification in Fiori Launchpad. It also allows us to create and react with actions that are initiated by user interaction.

GET_NOTIFICATION_TYPE:

As an importing parameter, we get IV_TYPE_KEY and IV_TYPE_VERSION, and exporting parameters are ES_NOTIFICATION_TYPE and ET_NOTIFICATION_ACTION. In this method, we can manipulate our notification types based on the type key and version. In addition, we can also define what all actions this type and version should support. In this method, we need to export ES_NOTIFICATION_TYPE,

es_notification_type-version  = iv_type_version.
es_notification_type-type_key = iv_type_key.
es_notification_type-is_groupable = abap_true.

The is groupable property, is used on Fiori Launchpad, when to classify your notifications by type.

ET_NOTIFICATION_ACTION is a type table. It allows us to add multiple action buttons on the notification.

 DATA ls_naction LIKE LINE OF et_notification_action.

 ls_naction-action_key = 'AcceptPOActionKey'.
 ls_naction-nature     = /iwngw/if_notif_provider=>gcs_action_natures-positive.

An action should have action_key and nature. Action_key is something you will require when you process the action while nature is semantic of the action. Action nature could be positive, negative or neutral.

The positive nature of the action will show the action button as green, negative will show red while neutral is plain.

I personally prefer, swtich-case statement on the IV_TYPE_KEY, and depending on the different type key I build es_notification_type and et_notification_action.

 

GET_NOTIFICATION_TYPE_TEXT:

This method allows you to frame the text, that we would like to see in the notifications and actions.

Importing parameters: IV_TYPE_KEY, IV_TYPE_VERSION, and IV_LANGUAGE.

Exporting parameters: ES_TYPE_TEXT and ET_ACTION_TEXT.

Using importing parameters you can create a unique combination of key, version, and language and build the notification text.

ES_TYPE_TEXT has the following properties:

template_public: Text template that will show notification publicly without any sensitive information.

template_sensitive: Text template for display with sensitive data in a notification

template_grouped: If classified by group, then this text template for will be used

description: The description of notification type

subtitle: The subtitle of the notification type

While building the template, you can have parameterized arguments which will be replaced at runtime with the notification parameter value.

lv_st_text = TEXT-024. "'Purchase order &1 for &2 by &3 requires your permission for approval'.
      REPLACE '&1' WITH '{requester_name}' INTO lv_st_text.
      REPLACE '&2' WITH '{cost}' INTO lv_st_text.
      REPLACE '&3' WITH '{quantity}' INTO lv_st_text.
      es_type_text-subtitle = lv_st_text.

In the above example, {requester_name}, {cost}, and {quantity} will be replace by the notification parameter value. the curly braces denote that it is the value of the parameter written inside the braces.

These parameters should match exactly with the parameters that have been used which creating notification.

The notification action text will be as:

ls_naction_t-action_key           = 'AcceptPOActionKey'.
ls_naction_t-display_text         = TEXT-004. "TEXT-004.
ls_naction_t-display_text_grouped = TEXT-005. "TEXT-005.
APPEND ls_naction_t TO et_action_text.

Here also, the action_key should match the key you have placed in GET_NOTIFICATION_TYPE method.

GET_NOTIFICATION_PARAMETERS:

The notification parameters which can be used to build the notification template. The method will add notification parameter in addition to notification parameters that are already passed with notification object itself.

The parameters are retrieved and returned based on the notification id, type, key, and language and filled in ET_PARAMETER of type notification_parameter.

HANDLE_ACTION:

The methods allow you to react on action triggered by user on the notification buttons defined in GET_NOTIFICATION_TYPE method. In this method, we will get the notificationid, type, key and the action key.

The importing parameters will allow to derive and identify the action. With the notification id, you can also get the notification parameters and should make the necessary action in accordance to the action key.

The return/exporting parameter of this method is if the we would like to return success (success) and delete(delete_on_return) the notification if success is returned, along with message text(action_msg_txt).

 

The next blog post is where we will review how all of it fits in.

Ciao.

Thanks

Prashil

/
Be the first to leave a comment
You must be Logged on to comment or reply to a post.