One of the interesting requirement I recently had was to set the priority of incoming e-mails based on different conditions. Conditions were, if user has marked the email as ‘High importance’ or the email subject contains some words like ‘Urgent’, ‘Last reminder’ etc. As usual the first place for getting something for this requirement was SCN. Though I didn’t get a complete solution, I got something from one of the threads.
First I checked whether it’s possible to set the priority like this. Yes..It’s possible manually via transaction code SWI1 and changing the priority. Now how to automate this.
For debugging an incoming email, we can set the debugging parameter in the following path,
SPRO->Customer Relationship Management->E-mail response management system->Define Repository or transaction CRMC_ERMS_REPOSITORY. For context ERMS, insert a property ‘DEBUG’ and value as ‘X’. This is a SAP hard-coded break that stops the routing and waits for you in sm50 to debug. Now you can debug in SM50.
Following are the steps I found after some debugging and analysis.
1. Go to tcode SWO1 and create a sub object for ERMSSUPRT2.
2. Redefine the method RuleExecution in the Z-object.
3. Now this method is the place where you have to make the code changes.
In our case, we created a custom table where we can store the words which needs to be considered as high priority. This allows if in case tomorrow we need some extra words also to be considered.
Insert following code here,
* Get specific words from customizing table SELECT * FROM ZPRIORITY_WORDS INTO TABLE lt_prio_key. IF sy-subrc = 0. * Loop to check if subject contains any string from the table maintained values. LOOP AT lt_prio_key INTO ls_prio_key. TRANSLATE ls_prio_key-key_string TO UPPER CASE. lv_sub_upper = sub . TRANSLATE lv_sub_upper TO UPPER CASE. IF lv_sub_upper CS ls_prio_key-key_string. lv_wi_text_import = 1. EXIT. ENDIF. ENDLOOP. ENDIF.
Now we got whether there are any words which is to be set to high. We need to check whether the email was sent with high priority also. Hence, add the following code.
lt_factbase = service_manager->factbase. * Get priority email setting CALL METHOD lt_factbase->get_by_xpath EXPORTING id_xpath = '/parts/EMAIL/PRIORITY/text()' RECEIVING rd_result = lv_prio.
Considering the values found from above, we have to set the priority of email. Hence, use the FM “SAP_WAPI_CHANGE_WORKITEM_PRIO” for setting the priority.
IF lv_wi_text_import EQ 1 OR lv_prio EQ 1. * Change priority CALL FUNCTION 'SAP_WAPI_CHANGE_WORKITEM_PRIO' EXPORTING workitem_id = flowitemid priority = '4' language = sy-langu. ENDIF. ENDIF.
4. We are done with coding part now. The next is to set the z-bject type is released.
5. And the last step is making the z-object as the delegated type for ERMSSUPRT2. This is to be done in SWO6 transaction.
Now go to your inbox and see whether the email with ‘High importance’ has come with priority ‘High’.
Please let me know if you have any queries.