Wednesday 16 October 2019

Alternative to “discover” Workflow executions coming from FIORI MyInbox and SBWP

In this Blog i’m gonna show you a alternative to a “common” question among the community: How do i know if a Workflow was executed coming from FIORI MyInbox or SBWP?

Well, there are a few ways to do that… This is one of them, a “coding” approach.

So let’s get to it!

I’ve created a simple Workflow that looks like this:

SAP ABAP Tutorial and Materials, SAP ABAP Learning, SAP ABAP Online Exam, SAP ABAP Study Materials

SAP ABAP Tutorial and Materials, SAP ABAP Learning, SAP ABAP Online Exam, SAP ABAP Study Materials

As you can see, a simples decision task, following by a condition check and 2 message actions.

On the decision task, just a simple decision:

SAP ABAP Tutorial and Materials, SAP ABAP Learning, SAP ABAP Online Exam, SAP ABAP Study Materials

Created a variable called GV_FIORI on the Workflow Container, it will receive a X when executed from FIORI.

SAP ABAP Tutorial and Materials, SAP ABAP Learning, SAP ABAP Online Exam, SAP ABAP Study Materials

So here, i’m checking if there is a X to it, it’s from FIORI, if not it was SBWP.

SAP ABAP Tutorial and Materials, SAP ABAP Learning, SAP ABAP Online Exam, SAP ABAP Study Materials

The FIORI Send mail action:

SAP ABAP Tutorial and Materials, SAP ABAP Learning, SAP ABAP Online Exam, SAP ABAP Study Materials

The SBWP Send mail action:

SAP ABAP Tutorial and Materials, SAP ABAP Learning, SAP ABAP Online Exam, SAP ABAP Study Materials

Our Workflow is all set!

Now, to be able to “know” if a Workflow came from FIORI, we have to implement the /IWWRK/BADI_WF_BEFORE_UPD_IB BADI. This BADI get’s executed only when it comes from a FIORI Call, so inside of it we’ll place our code to deliver a X on the GV_FIORI container variable of the Workflow process. So now the WF instance can be aware where it came from…

So i’ve created a implementation

SAP ABAP Tutorial and Materials, SAP ABAP Learning, SAP ABAP Online Exam, SAP ABAP Study Materials

Placed my Workflow ID and step ID on the filter:

SAP ABAP Tutorial and Materials, SAP ABAP Learning, SAP ABAP Online Exam, SAP ABAP Study Materials

So now let’s implement the method:

SAP ABAP Tutorial and Materials, SAP ABAP Learning, SAP ABAP Online Exam, SAP ABAP Study Materials

Place the code below on it:

method /iwwrk/if_wf_wi_before_upd_ib~before_update.
  data: lt_cont type table of swr_cont,
        ls_root type swwwihead,
        ls_cont type swr_cont.

  "Get the parent Workitem...
  call function 'SWI_GET_ROOT_WORKITEM'
    exporting
      wi_id                   = is_wi_details-wi_id
    importing
      root_item               = ls_root
    exceptions
      workitem_does_not_exist = 1
      others                  = 2.
  if sy-subrc <> 0.
    "Place the error message on the CT_RETURN...
    exit.
  else.
    "Write data to the variable
    ls_cont-element = 'GV_FIORI'.
    ls_cont-value   = 'X'.
    append ls_cont to lt_cont.
    "Write variable back to the Container...
    call function 'SAP_WAPI_WRITE_CONTAINER'
      exporting
        workitem_id      = ls_root-wi_id
      tables
        simple_container = lt_cont.
  endif.

endmethod.

So now we’re all set! Start a few Workflows, and execute from SBWP and MyInbox app, you’ll see the below results:

SAP ABAP Tutorial and Materials, SAP ABAP Learning, SAP ABAP Online Exam, SAP ABAP Study Materials

No comments:

Post a Comment