The following steps describe how we can create notifications. The scenario here is to create a notification through a simple workflow template that will take notification text and agent as input and simply forward the notification with the text to that agent. I will be using a method instead of a function module. If you prefer to use a function module, you can still follow up (I’ll note what you need to change).
- Create a workflow utility class, or use one if already exists – Transaction SE24 (If using function modules, then, create or use a workflow utility function group – Transaction SE37).
- Implement the IF_WORKFLOW interfacewhich will implicitly implement BI_OBJECT and BI_PERSISTENT (this step is not applicable to function modules)
- Under the “Properties” tab, enterSWFCO in the “Type group/Object type” table and hit Enter (for function module, type “TYPE-POOLS swfco” in the TOP include).
- Click the “Parameters” button todefine needed parameters that will be provided by the workflow template. Notethat the IM_WI_ID is mandatory. The text field IM_TEXT is not “technically”mandatory but it is definitely needed or otherwise this whole exercise ispointless. You will need 5 importing parameters: IM_WI_ID (the calling workitem), IM_TEXT (notification text), IM_AGENT_TYPE (receiver type: US for user,S for position, P for person, O for organization unit, etc.), IM_AGENT_ID(receiver ID depending on the agent type), IM_COMMIT (flag whether to commit).2 parameters can be defined as export parameters: EX_WI_ID (work item ID forthe notification task that was just created), and EX_WI_HEADER (Header fromtable SWWWIHEAD).
Note that swfco_wi_rc_latest_end is a constantdefined in type pool SWFCO that is used in methodCL_SWF_RUN_WIM_DEADLINE=>GET_DEADLINE_TYPE. If you don’t set fieldLS_PROP-WI_DH_STAT with an expected value, function module SWW_WI_CREATE willcreate a short dump. Also, feel free to modify the code to add more agents.
The code in the screenshot (you will need some adjustment for the function module):
- Save and activate the class andthe method
Integratingthis method into a Workflow template
For more information on how to build workflow templates and tasks, refer to the “Practical Workflow forSAP” book (http://www.sap-press.com/products/Practical-Workflow-for-SAP-(2nd-Edition).html)or to SAP’s help web page (help.sap.com)
- For the function module, you will need to create a corresponding business object method (transaction SWO1). Go to that transaction, enter an object name (say ZWFOBJ), and then place the cursor on the methods node. Click “Create” icon then click Yes when asked whether you want to “Create with function module as template?” Enter the function module name then continue keeping all defaults as they are. You will then be asked whether you want the code auto-generated and you will need to select Yes. A new method will be created that has the same function module name without any underscores.
- Enter standard task details asshown (for function modules, you will need to change the Object Category to BOR “Object Type” and then provide the business object and method names defined earlier)
- When asked whether to transfermissing parameters, click “Yes”
- Click the “Auto-Generate” buttonto link the task parameters to the method parameters as shown in the screenshot
- After saving, the system willgenerate a task ID (in my case the number was 90000075). The task from now onwill be TS90000075. This number will depend on the system this exercise isbeing performed in.
- There is no need to set up thetask agent assignment (menu option: Additional data à Agent assignment à Maintain) since thistask is a “background” task.
- Click the “Container” tab andenter all parameters you’ll need to use in the workflow. In my case, I createdthe following:
- IM_TEXT_PARAM (type: TEXT20)so that I can pass text when running the workflow
- IM_AGENT (type: SWHACTOR) sothat I can determine the notification agent dynamically when starting theworkflow
- Click the “Binding” button again,and bind the container’s &_WORKITEM.TOPFLOW& to the task’s&IM_WI_ID& parameter. Also, map the agent into the&IM_AGENT_TYPE& and &IM_AGENT_ID&. Optional: Map some text tothe task’s &IM_TEXT& parameter. In my case, I created an inputparameter called im_test_param for the workflow that I pass on to the task.This way, every time I create a workflow instance I can change the text thatwill show up in the user’s inbox and in the workflow log.
- Click the green check mark toreturn the step definition, then again, click the green check mark to return tothe main Workflow builder screen
- Save and Activate the workflowtemplate
- Since this is a customdevelopment that “defies” SAP standard for creating notifications other than“missed-deadline” there is another trick you might want to consider. In theworkflow log (transaction SWI1), any task of type D will show as “MissedDeadline” as in the below screenshot. Technically, it will not make adifference, but if you are very picky as a workflow administrator, you canoverwrite this description. The following steps describe how you can changethat description.
- Click the “Maintain” button andyou will get the following warnings:
If you are OK with overwriting SAP data, thenproceed.
- Find all entries of type D(Deadline Work Item). In front of the corresponding entry, edit the text asrequired for all available languages. For the purpose of this exercise, I’llchange only the English text to “Custom Notification.” Note that you will needto attach this change to a development request which makes sense since this isa client-independent table.
- Now, let’s test our workflow;go to transaction SWUS and enter the workflow template ID generated earlier(WS90000039 in my case)
- Once you see the notification work item created, go to your Universal WorkList in EP and display your inbox
- The notification should bethere as displayed above.