Friday, 5 January 2024

SAP Business Workflow – Trigger Workflow Behind Tcode: CJ20N

There was a requirement in a project that the users wants to control project creation with workflow. Project Builder (CJ20N) screen does not have standard workflow process working behind. First of all we need to find the triggering event works behind Project Builder (CJ20N) screen. In my case I need to start workflow process after creating project.

In this blog I will show you how to reach the standard class, events and event parameters to trigger and design a workflow.

Steps that we need to follow:

Step 1- Figure Out How To Trigger The Workflow

Step 2- Create Global Class

Step 3- Event Linkage Configuration

Step 4- Triggering Workflow

Step 5- Debug and Find Parameters

Step 1- Figure Out How To Trigger The Workflow:

The questions comes up through my mind.

  • Is there a standard workflow provided for transaction ?
  • Which events are triggered ?
  • What is the standard class or business object for the transaction?

To answer these questions I start searching and find some FMs which are;

  • SWE_EVENT_CREATE
  • SWE_CREATE_EVENT
  • SAP_WAPI_CREATE_EVENT
  • SWE_EVENT_CREATE_IN_UPD_TASK
  • SWE_EVENT_CREATE_FOR_UPD_TASK

And tried to debug those FM for finding the events and the event container but didn’t work for me.

So I decided to check event trace. For finding the event we gonna go Tcode SWELS and Switch Off the trace and Switch On again to generate the event trace.


After we switch on again, go Tcode SWEL for finding out what is the class and the event for our process. Our standard class and event is CL_PS_WBSELEMENT_EVENT-WBSELEMENTCREATED.


Step 2- Create Global Class:

We need a global class for triggering the workflow we gonna design and also we need it for reaching the event parameters we find in step 1.

Step 2.1 Find Out What We Need

When we go to SWE2 for the event linkage and find our class and its event and double click on it we see how the standard event is configured and we need to make a ‘z’ configuration.



In this standard configuration we saw that SAP used an interface BI_EVENT_HANDLER_STATIC that we need in our global class to trigger the workflow and reach the event parameters.

Step 2.2 Create Global Class Now

Go to SE24 and create a class and implement the interface.


There is a method of an interface called ON_EVENT and when you implemented the interface it will show up in the methods section.


Let’s leave this method for now after steps 3 and 4 we are gonna use this to reach event parameters.

Step 3- Event Linkage Configuration

In Step 2.1 we found the standard version of linkage for our class and its event now we are gonna make the configuration for trigger the workflow.

Go to transaction SWDD to build a workflow.


Once you create your workflow you need to activate it to have a workflow number which starts with WS. We need that WS*** number for configuration in SWE2.

Go to transaction SWE2 and copy our standard class with the needed event. For my case I need the creation event.


Receiver type is our workflow number that starts with WS*** and class name will be our Z class so we can reach the parameters. The checkbox Linkage Activated must be chosen to complete  and generate configuration.

Go to transaction SWDD again and implement the Start Event to trigger workflow.


Do not forget to activate and make the bindings of the event.

Step 4- Triggering Workflow

Now we all set. For triggering workflow all we need is go transaction CJ20N and create a project. Once the project created the workflow will be triggered and can be seen from transaction SWIA.


Step 5- Debug and Find Parameters

Place an external debug for user SAP_WFRT on the Z class ON_EVENT method.



Complete the steps for CJ20N. On the debugger screen’s locals tab you will see EVENT_CONTAINER and inside of the event container you can reach the parameters you need.



And you can simply use the below code in ON_EVENT method to get those parameters to use. For my case I needed WBSELEMENTINTERNALID you can use any other element container parameter name.

TRY.
    CALL METHOD event_container->get
      EXPORTING
        name  = 'WBSELEMENTINTERNALID'
      IMPORTING
        value = lv_wbsinternalid.
  CATCH cx_root.
ENDTRY.

No comments:

Post a Comment