METHOD /iwngw/if_notif_provider~get_notification_parameters.
DATA(lv_lang) = sy-langu.
SET LANGUAGE lv_lang.
ENDMETHOD.
METHOD /iwngw/if_notif_provider~get_notification_type.
DATA ls_naction LIKE LINE OF et_notification_action.
IF iv_type_key = 'EXPIRING_ANL'.
" Return Notification Type and Version
es_notification_type-version = iv_type_version.
es_notification_type-type_key = iv_type_key.
es_notification_type-is_groupable = abap_true.
ls_naction-action_key = 'SendMailActionKey'.
ls_naction-nature = /iwngw/if_notif_provider=>gcs_action_natures-positive.
APPEND ls_naction TO et_notification_action.
ls_naction-action_key = 'DismissActionKey'.
ls_naction-nature = /iwngw/if_notif_provider=>gcs_action_natures-negative.
APPEND ls_naction TO et_notification_action.
ENDIF.
ENDMETHOD.
METHOD /iwngw/if_notif_provider~get_notification_type_text.
DATA ls_naction_t LIKE LINE OF et_action_text.
DATA lv_tmptext TYPE string.
DATA lv_tmpattr TYPE string.
DATA lv_st_text TYPE string.
DATA lv_period TYPE string.
CLEAR:es_type_text,et_action_text.
DATA(lv_lang) = sy-langu.
SET LANGUAGE iv_language.
IF iv_type_key = 'EXPIRING_ANL'.
es_type_text-template_public = 'A plant will drop-off support soon'.
lv_tmptext = 'The energy plant &1 will drop-off support on &2'.
REPLACE '&1' WITH '{plant_id}' INTO lv_tmptext.
REPLACE '&2' WITH '{expires_at}' INTO lv_tmptext.
es_type_text-template_sensitive = lv_tmptext.
es_type_text-description = 'End of support of a plant'.
lv_tmptext = 'Soon &1 plant(s) drop-off support'.
CONCATENATE '{' /iwngw/if_notif_provider=>gcs_parameter_reserved_names-group_count '}' INTO lv_tmpattr.
REPLACE '&1' WITH lv_tmpattr INTO lv_tmptext.
es_type_text-template_grouped = lv_tmptext.
ls_naction_t-action_key = 'SendMailActionKey'.
ls_naction_t-display_text = 'Send reminder E-Mail'.
ls_naction_t-display_text_grouped = 'Send mass E-Mail'.
APPEND ls_naction_t TO et_action_text.
ls_naction_t-action_key = 'DismissActionKey'.
ls_naction_t-display_text = 'Dismiss'.
ls_naction_t-display_text_grouped = 'Dismiss all'.
APPEND ls_naction_t TO et_action_text.
ENDIF.
SET LANGUAGE lv_lang.
ENDMETHOD.
METHOD /iwngw/if_notif_provider~handle_bulk_action.
RETURN. " No implementation for our use-case needed
ENDMETHOD.
METHOD /iwngw/if_notif_provider~handle_action.
TYPES: BEGIN OF ty_lines,
line TYPE char255,
END OF ty_lines.
DATA: lt_email_body TYPE STANDARD TABLE OF ty_lines,
lt_notif_id TYPE /iwngw/if_notif_provider=>ty_t_notification_id,
lv_email_subject TYPE string VALUE 'A plant will drop-off support soon',
lv_email_body TYPE string VALUE 'the energy plant &1 will drop-off support on &2.'.
IF iv_notification_id IS INITIAL OR iv_action_key IS INITIAL.
es_result-success = abap_false.
es_result-action_msg_txt = 'Error: Key or ID initial'.
ELSE.
CASE iv_action_key.
WHEN 'SendMailActionKey'. "Send E-Mail
" Prepare and send E-Mail to the respective E-Mail address
DATA(lt_notifications) = get_notifications_by_notifiid( iv_notifi_id = iv_notification_id ).
LOOP AT lt_notifications INTO DATA(ls_notification).
IF ls_notification-name = 'plant_id'.
DATA(lv_plant_id) = ls_notification-value.
ELSEIF ls_notification-name = 'expires_at'.
DATA(lv_expires_at) = ls_notification-value.
ENDIF.
ENDLOOP.
DATA(lv_plantowner) = get_plantowner_by_plantid(lv_plant_id).
REPLACE '&1' WITH lv_plant_id INTO lv_email_body.
REPLACE '&2' WITH lv_expires_at INTO lv_email_body.
APPEND VALUE #( line = 'Dear Sir or Madam,' ) TO lt_email_body.
APPEND VALUE #( line = lv_email_body ) TO lt_email_body.
APPEND VALUE #( line = '' ) TO lt_email_body.
APPEND VALUE #( line = 'Yours sincerely,' ) TO lt_email_body.
APPEND VALUE #( line = 'The Plant-Compensation Team' ) TO lt_email_body.
CALL FUNCTION 'EFG_GEN_SEND_EMAIL' " uses your logged-in E-Mail account
EXPORTING
i_title = lv_email_subject
i_sender = sy-uname
i_recipient = lv_plantowner " a table full of recipients is also possible
i_flg_commit = 'X'
i_flg_send_immediately = 'X'
TABLES
i_tab_lines = lt_email_body
EXCEPTIONS
not_qualified = 1
failed = 2
OTHERS = 3.
IF sy-subrc = 0.
es_result-action_msg_txt = |{ 'E-Mail successfully sent to' }{ lv_plantowner }|.
ELSE.
es_result-action_msg_txt = 'Error while sending the E-Mail'.
ENDIF.
WHEN 'DismissActionKey'. "Ignore notification
es_result-action_msg_txt = 'Plant drop-off dismissed'.
WHEN OTHERS.
ENDCASE.
es_result-success = abap_true.
es_result-delete_on_return = abap_true.
" Delete notification for cleanup
lt_notif_id = VALUE #( ( id = iv_notification_id type_key = iv_type_key type_version = iv_type_version ) ).
TRY.
/iwngw/cl_notification_api=>delete_notifications(
EXPORTING
iv_provider_id = 'ZPW_LOC_NOTIFY'
it_notification_id = lt_notif_id
).
CATCH /iwngw/cx_notification_api INTO DATA(lrx_api).
" Add event handling
ENDTRY.
ENDIF.
ENDMETHOD.
REPORT zpw_get_dropoff_plants.
DATA lt_notif TYPE /iwngw/if_notif_provider=>ty_t_notification.
DATA lt_recipient TYPE /iwngw/if_notif_provider=>ty_t_notification_recipient.
DATA lt_nav_params TYPE /iwngw/if_notif_provider=>ty_t_navigation_parameter.
DATA lt_semantic_params TYPE /iwngw/if_notif_provider=>ty_t_notification_param_bundle.
DATA lt_notif_parameter TYPE /iwngw/if_notif_provider=>ty_t_notification_parameter.
DATA(lv_launchpad_role) = 'ZEEGBILLDISP'. "Your role having the launchpad notification catalog assigned
DATA(lv_type_key) = 'EXPIRING_ANL'. "Define your type key to identify this kind of notification
DATA lv_provider_id TYPE /iwngw/if_notif_provider=>ty_s_provider-id VALUE 'ZPW_LOC_NOTIFY'. " Your created provider ID
" Scan the database for upcoming drop-offs
DATA(lt_plants) = zcl_monitor_utilities=>check_for_dropoff_plants( ).
IF lines( lt_plants ) > 0.
" Get all users which are assigned to the launchpad notification role --> All should be notified
SELECT uname FROM agr_users INTO TABLE @DATA(lt_user)
WHERE agr_name = @lv_launchpad_role AND from_dat < @sy-datum AND to_dat > @sy-datum.
LOOP AT lt_user INTO DATA(lv_user).
APPEND VALUE #( id = lv_user ) TO lt_recipient.
ENDLOOP.
" Go through each plant and send an individual notification
LOOP AT lt_plants INTO DATA(ls_plant).
" For semantic navigation (via semantic object and action), we add the columns of the CDS table in the Fiori App
lt_nav_params = VALUE #( ( name = 'plantId' value = ls_plant-id ) ).
APPEND VALUE #( name = 'plant_id' value = ls_plant-id type = /iwngw/if_notif_provider=>gcs_parameter_types-type_string is_sensitive = abap_false )
TO lt_notif_parameter.
APPEND VALUE #( name = 'expires_at' value = ls_plant-expires_at type = /iwngw/if_notif_provider=>gcs_parameter_types-type_string is_sensitive = abap_false )
TO lt_notif_parameter.
lt_semantic_params = VALUE #( ( language = sy-langu parameters = lt_notif_parameter ) ).
lt_notif = VALUE #( (
id = zcl_notification_provider=>get_notifiid_by_params( iv_plant = ls_plant-id iv_expiredate = ls_plant-expires_at )
type_key = lv_type_key
type_version = '1'
priority = /iwngw/if_notif_provider=>gcs_priorities-medium
actor_id = sy-uname
actor_type = ''
actor_display_text = sy-uname
recipients = lt_recipient
parameters = lt_semantic_params
navigation_target_object = 'plantmgmnt'
navigation_target_action = 'manage'
navigation_parameters = lt_nav_params
) ).
TRY.
/iwngw/cl_notification_api=>create_notifications(
EXPORTING
iv_provider_id = lv_provider_id
it_notification = lt_notif ).
CATCH /iwngw/cx_notification_api INTO DATA(lrx_api).
" Add error handling
ENDTRY.
COMMIT WORK.
ENDLOOP.
ENDIF.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
28 | |
6 | |
4 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 |