`
evangxli
  • 浏览: 223635 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

转 Display Dynamic Attachments in Work Item in Workflow

 
阅读更多

Display Dynamic Attachments in Work Item in Workflow

By Anirban Bhattacharjee, KPIT Cummins and Infosystems from Link

Purpose: The purpose of this article is to show you how to display dynamic attachments in work items in workflow

Business Scenario: This is useful in all workflows across all modules. The scenario I am taking for an example is the Travel and Expense Workflow, related to the PR05 and TRIP transactions. When an employee creates an expense report in the T&E Module, he needs to attach receipts to justify the expense. The application in R/3 (PR05 / TRIP) or the ESS MSS Application via portal processes this attachment to the GOS Attachments folder. After the attachment the employee submits the TRIP which triggers the workflow and routes the work item for approval. In the workflow just before the foreground work item creation, we can read the GOS Folder and attach the documents as a physical attachment.

But many times the employee forgets to do the attachment and completes it after TRIP submission and hence work-item creation. The approver now cannot see this new document attached after workflow trigger and TRIP Submission.

This article will show how to make this happen. You will be able to enable a feature such that approvers can view all attachments done after TRIP Submission and hence the workflow trigger.

Process: The process will involve the following steps

·         Create a custom business object that will read the GOS Attachment. This method will be called as the default method in the BOR.

·         Create a custom workflow for demo. In this workflow we will use the main SAP Business Object for TRIP; BUS2089 (Employee Trip).

·         We will instantiate the custom BOR in the workflow and attach it to the _ADHOC_OBJECT element to create the dynamic GOS attachment link.

·         We can test in Business Workplace (SBWP) or the UWL in Portal if you have portal in your project.

STEP 1: Create a Custom Business Object

(I am not going into the details of business object creation. That is not in this document scope)

We call this business object as ZTRIP_NEW (Display TRIP Attachments in Real Time).

We create a method GOS_ATTACH_DISPLAY as shown below

(Please overlook the other methods. They are not related to this topic)

This method has no parameters

This is an instance depended method, that is the BOR must be instantiated to call this method

In order to display the GOS Attachments, we will call the function module GOS_ATTACHMENT_LIST_POPUP.

Here we will pass the importing parameter IP_MODE as ‘D’ to ensure that the attachments can only be displayed.

The approver should not be able to add or remove any attachments.

The code you will write in this method is shown below

begin_method gos_attach_display changing container.

DATA: is_object TYPE sibflporb.

is_object-typeid = 
'BUS2089'.
is_object-catid  = 
'BO'.
is_object-instid = object-
key.
* GOS Attachments
CALL FUNCTION 'GOS_ATTACHMENT_LIST_POPUP'
  
EXPORTING
    is_object             = is_object
    ip_check_arl          = 
'X'
    ip_check_bds          = 
'X'
    ip_notes              = 
'X'
    ip_attachments        = 
'X'
    ip_urls               = 
'X'
    ip_mode               = 
'D'
*  IMPORTING
*    EP_SAVE_REQUEST       =
*  TABLES
*    IT_OBJECTS            =
          .
end_method.

Please note that we are building the TRIP key here along with Business Object (BUS2089 for TRIP) and Category ID (BO for Business Object).

This function module will read this unique key combination of the instance (TRIP and Employee Number) with the Business Object ID and Cat ID and display the attachment list.

Now once the method is created, we will mark this method as a default method. I will explain later why we are doing this.

In the BOR Screen, navigate to the Basic Data (CTRL+SHIFT+F1) of the BOR by clicking on the HAT Icon as shown

We navigate to this screen now. Click on the DEFAULTS Tab

Enter the Method GOS_ATTACH_DISPLAY and pass attribute as TRIP Number. This will display in the work item as a link

We save and activate the BOR and mark the method and the BOR as Implemented and Released.

(This is a standard process to be followed when creating a custom BOR).

The above process completes our first step of creating and activating or Custom BOR that will read the GOS attachment.

STEP 2: Create a Custom Workflow

We will create a custom workflow with simply two steps.

The first step will instantiate our custom BOR, second step will be the user decision that will be sent to the approver.

The workflow will be modeled on the standard SAP business object BUS2089 as the main business object.

Run PFTC and create the workflow template, name it as shown and save it

Navigate to the container tab and create a container element called TRIP as shown

Mark this element as importing and mandatory

The element is created. Now navigate back to Basic Data to enter the work item text

Save the template and then click on Workflow Builder, to call the builder to design the workflow

STEP 3: Instantiate the Custom Business Object and continue the workflow creation.

Now we will create a background task / activity to instantiate our custom business object ZTRIP_NEW.

In this step we will use a standard task where we will call the method GENERICINSTANTIATE from BOR SYSTEM as shown

 

The container element created for this task from method GENERICINSTANTIATE are shown below

ObjectKey: Points to SWOTOBJID- OBJKEY. This will contain the TRIP Keys. Has no initial value.

ObjectType: Points to SWOTOBJID- OBJTYPE. It will contain the Business Object that needs to be instantiated.

In this case, it is ZTRIP_NEW; hence this will be the default value

 

ObjectInstance: This contains no reference to any BOR. This will get the instance of the BOR specified at runtime.

In this case the BOR passed via ObjectType is ZTRIP_NEW. Hence the element ObjectInstance will contain the instance of this custom BOR.

The binding in the method in task is shown

Now the task is created. Save it and come back to the workflow. The workflow prompts for the auto bindings

Accept and save the bindings

In the workflow, mark this container ObjectKey as importing. While testing pass the concatenated string of Employee Number and TRIP No.

(This is done to simplify the demo. In real time, this key can be built from the event call via event containers)

Now create an element container to store the above instance for ZTRIP_NEW as shown.

Save this element and the workflow

Now go back to the task created and bind this element created as shown

 

This will pass the run time instance of our custom business object ZTRIP_NEW to the container we created of the same name.

Now use container operation step to pass this instance to the Standard Workflow container element _Adhoc_Objects

Note that I have simply extended the table.

The container _Adhoc_Objects by default will also contain the default method of our Main Standard SAP Business Object BUS2089.

We are simply extending the table to call our GOS Dynamic BOR as well.

The effect will be in the work item we will get two links one for the standard BOR and one for our custom BOR.

Important: Whenever you pass the instance of any business object to this element _Adhoc_Objects, it creates a link in the work item.

On clicking this link, it executes the Default Method of the BOR. This is the reason why we marked our method GOS_ATTACH_DISPLAY as default.

You can pass the instance of the standard BOR BUS2089 also to this container as shown

Now create the USER Decision Step and send to Initiator (For DEMO Simplicity)

Final workflow looks as shown

Our DEMO is now ready to be tested.

First let us display a TRIP via PR05 and see what is there in the attachments

Display attachment via the menu path as shown

 

So this TRIP has only one attachment now.

We run T-Code SWUS to test the workflow.

Pass the TRIP Details and concatenated data of PERNR and TRIP

Work item in SBWP

Note under Objects and Attachments, we see both the attachments links.

The first link for the Standard Display Method in standard BOR and second link points to our Custom BOR for Dynamic Links.

Click the Display Attachments Link

We can see one attachment here. Now we go and attach one more attachment in the TRIP as shown

Now coming back to the same work item

Click on the Display Attachments link again. It should show the new attachment also

 

So we have successfully configured Dynamic Attachments in the workflow.

Clicking on the link Employee TRIP will display the TRIP since BUS2089 has Display Method as Default

The TRIP Gets Displayed

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics