This article dives into the process of creating a custom workflow for managing purchase contract approvals. While a standard workflow template exists, it might not always align perfectly with specific business requirements. This scenario necessitates a custom approach due to the following factors:
- Approver Detail Management: The standard template likely relies on pre-defined agent IDs stored in SPRO config. However, in this case, approver details are maintained within a custom table managed by the client-side administration team. A custom workflow offers greater flexibility to accommodate this dynamic approach to approver management.
- Attaching PDF Documents to Work Items: The standard workflow template does not have step to attach documents stored in the DMS as PDF attachments within work items to display it in the My Inbox Fiori app.
- Deadline Monitoring for Additional Approvers: The standard template,does not have deadline monitoring hence we would require custom template to add deadline monitoring.
Step-by-Step Guide to Build the Custom Workflow:
- Access Workflow Builder (T-code SWDD): Begin by launching the Workflow Builder using the transaction code SWDD.
- Define Basic Data: In the Basic Data section, enter a descriptive name and abbreviation for your custom workflow template.
- Configure Start Events: Navigate to the "Start Events" tab and define the triggering event for the workflow. The triggering object is "BUS2014," and the event is "ReleaseStepCreated," which triggers after each release level.
- Set Up Event Binding: The Event Binding section is crucial for specifying details about the purchase contract that the workflow will process. Here, you'll define the Event Object (Purchasing Contract), Event Creator (Purchase Contract creator/Initiator), and Release Code (to specify which release code triggers the workflow).
- Activate Template and Verify Linkage (T-code SWETYPV): Before proceeding, activate the custom workflow template. Then, use the transaction code SWETYPV to verify if the linkage is active for object type "BUS2014" and receiver type (your custom workflow template number). Click the detail button to confirm linkage activation.
- Create Steps: Construct the workflow steps using the following sequence:
- Step 1: Get Approver Details: Create a step named "Get Approver Details" of type "Activity." Within this step, define a workflow container element named "Approver Details" to store the retrieved information.
- Create Task: In the control tab of the "Get Approver Details" step, you can create a task. This task can also be created using the transaction code PFTC.
- Implement Processing Logic: Within the "Object Method" field of the task or directly in the step, choose "Class" as the Object Category. Enter the name of the class you've created specifically for this workflow. Finally, specify the method within the class that contains the processing logic for retrieving approver details from the custom table.
Note: When creating the class for the workflow, ensure it implements the following interfaces: BI_OBJECT, BI_PERSISTENT, and IF_WORKFLOW. Necessary bindings should also be established for the "Get Approver Details".
- Attach PDF Document: create another step named "Attach PDF". Follow similar steps as outlined for the "Get Approver Details" step to implement the logic for attaching a PDF document from the DMS (Document Management System) to the work item.
Hints for Attaching PDF Documents:
- Utilizing DRAD Table: The process begins by querying the DRAD table. This table serves as a link between documents and the SAP objects they are associated with. By providing the relevant information, you can retrieve the document key (dokob) and object key (objky) from the DRAD table.
- Extracting Document Details with CVAPI_DOC_GETDETAIL: With the document key (dokob) in hand, you can leverage the function module 'CVAPI_DOC_GETDETAIL'. This function module retrieves detailed information about the document in the internal table 'pt_files' that potentially contains information about attached files.
- Obtaining Document URL with SDOK_PHIO_GET_URL_FOR_GET: If 'pt_files' from CVAPI_DOC_GETDETAIL indicates the presence of attached files, you can extract the physical document ID (ph_objid) from the table. Subsequently, the function module 'SDOK_PHIO_GET_URL_FOR_GET' can be used to retrieve the URL for the specific document.
- Attaching PDF using ABAP HTTP Class: Finally, the ABAP HTTP class (cl_http_client) comes into play. By creating an instance of this class using 'CREATE_BY_URL' (since the document URL is available), you can initiate an HTTP request. The 'send' method transmits the request, followed by 'receive' to capture the response. The data can be accessed as a string using 'get_data'. Once the data is retrieved, if the connection is no longer required than it can be closed by using 'close' method.
- Attaching data to work_item: Use function module ' SAP_WAPI_ATTACHMENT_ADD ' to add attachment to workitem.
By following these steps within the custom workflow, you can effectively retrieve and attach relevant PDF documents from the DMS.
Once the preceding steps are completed, we reach the "dialog step". Dialog steps are decision-making points within a workflow. You can either reuse a standard step or create a custom one (the reasons for choosing a custom step will be explained later).
Create a step named 'Release of purchase contract' enter the name abbreviation. 'Object category ': 'Business Object' , 'Object type' : 'BUS2014' , 'Method' : 'Single release'.Now check the object method with dialog checkbox. in the object method binding should be done for release code as the method single release in bus2014 as release code as mandatory importing parameter.
Task Binding:
- Bind the purchase contract event object to the task in task binding.
Agent Assignment:
- Go to Agents --> Expression.
- Enter the expression: 'US' + current approver user ID (This assigns the task to the user with the specified ID prefixed with "US").
Task Properties:
- Go to Task Properties --> Agent Assignment for Task --> Attributes.
- Change the assignment type to General Task.
Verification: The Agent Assignment light should turn green, indicating successful configuration.
- To capture this agent assignment in the tr, use report RHMOVE30.
Activation and Workflow Trigger:
- Activate the workflow template.
- Creating a purchase contract will trigger the workflow.
- A work item will be available in SBWP.
Note : Additional configuration is required in SPRO [Sap NetWeaver-> SAP Gateway Service Enablement->Content-> Workflow Setting->Maintain Task and Decision Option] to make the work item accessible within the My Inbox Fiori app. Create an entry using workflow id and step id --> [Decision keys] enter the decision text which should be displayed in the myinbox app.
Configuring Visualization (SWFVISU):
- To display the purchase contract details within My Inbox, navigate to transaction code SWFVISU.
- create an entry for the task associated with the dialog step ("Release of Purchase Contract").
- Configure the task visualization.
- Select Inbox Generic App as the visualization type.
- for the Visualization Parameter Value field, refer the standard task's TS*XXXX*172.
To Handle action for decision keys maintained in maintain task and decision key , SAP provides the Business Add-In (Badi) /IWWRK/BADI_WF_BEFORE_UPD_IB.
The standard implementation for purchase contract approval serves as a reference point. You can access its details through enhancement implementation MM_PUR_CTR_APPROVE_ACTIONS and Badi implementation MM_PUR_CTR_APPROVE_ACTIONS (class implementation CL_MM_PUR_CTR_APPR_ACTION_BADI).
With the workflow template development complete, the workflow will now automatically trigger after every purchase contract creation. This will generate a corresponding work item that will be delivered directly to the designated approver's My Inbox Fiori app. This streamlined approach facilitates efficient purchase contract management and approval processes.