Mark Peeters
Read all my blogsCreating the alert:
On the CONTAINER tab, you can add objects that you want to use in the text. In this example we use the OBJECT_ID that we fill with the service order number. If you add custom objects you will need to fill the object in the Alert Class, we will do this for the OBJECT_ID object.
Copy Alert Class:
Because we want to be able to change the data used in the alert (users and Objects) we copy this class to ZCL_ACTION_EXECUTE. We change the Method TRIGGER ALERT to determine the manager of the employee responsible of the service order.
* now filter the employees.
LOOP AT lt_partner INTO ls_partner
WHERE REF_PARTNER_FCT EQ ‘00000014’. “gc_partner_pft-employee.
CLEAR: ls_recipients.
CALL FUNCTION ‘BP_CENTRALPERSON_GET’
EXPORTING
iv_bu_partner_guid = ls_partner-bp_partner_guid
IMPORTING
ev_username = ls_recipients-uname
EXCEPTIONS
no_central_person = 1
no_business_partner = 2
no_id = 3
OTHERS = 4.
IF sy-subrc EQ 0 AND
ls_recipients-uname IS NOT INITIAL.CALL FUNCTION ‘BBPU_GET_ORGSTRUCTURE_OF_USER’
EXPORTING
username = ls_recipients-uname
IMPORTING
position_id = lv_position
EXCEPTIONS
no_org_data_found = 1
OTHERS = 2.
IF sy-subrc = 0.MOVE lv_position TO lv_sobid.
CALL FUNCTION ‘RH_GET_LEADING_POSITION’
EXPORTING
plvar = ’01’
otype = ‘S’
sobid = lv_sobid
date = sy-datum
TABLES
leading_pos = lt_lead_pos
EXCEPTIONS
no_lead_pos_found = 1
OTHERS = 2.
IF sy-subrc = 0.READ TABLE lt_lead_pos INTO ls_lead_pos INDEX 1.
CALL FUNCTION ‘BBP_OM_STRUC_GET_USER_FROM_POS’
EXPORTING
position = ls_lead_pos-objid
sel_date = sy-datum
ppoma_call = ‘X’
authority_check = ‘ ‘
IMPORTING
user = lv_user
EXCEPTIONS
path_not_found = 1
error_reading_structure = 2
no_roots = 3
invalid_roots = 4
internal_error = 5
holder_is_ambiguous = 6
user_is_not_assigned = 7
OTHERS = 8.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDIF.
ENDIF.clear ls_recipients.
ls_recipients-uname = lv_user.
INSERT ls_recipients INTO TABLE lt_recipients.
ENDIF.
ENDLOOP.
CALL FUNCTION ‘SWC_ELEMENT_SET’
EXPORTING
element = ‘OBJECT_ID’
field = ls_orderadm_h_ref-object_id
TABLES
container = lt_container
EXCEPTIONS
OTHERS = 1.
Create Action BaDI:
The Alert is triggered by an action so we need to create a new implementation of the BaDI EXEC_METHODCALL_PPF so that we can call our own Alert Class. In SE18, create a new implementation and add the filter value ZTRIGGER_ALERT_PRIO.
METHOD IF_EX_EXEC_METHODCALL_PPF~EXECUTE .
DATA: lc_action_execute TYPE REF TO zcl_action_execute.
CREATE OBJECT lc_action_execute.
* copy document
CALL METHOD lc_action_execute->trigger_alert
EXPORTING
io_appl_object = io_appl_object
ip_application_log = ip_application_log
ip_action = ip_action
ip_preview = ip_preview
ii_container = ii_container
IMPORTING
rp_status = rp_status.ENDMETHOD.
Create Action:
In the new action we need to set the Method Call to our new BaDI implementation and add the Processing Parameter Category with name of our Alert Category.