sexta-feira, 18 de outubro de 2019

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

Hello,
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:
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:
Created a variable called GV_FIORI on the Workflow Container, it will receive a X when executed from FIORI.
So here, i’m checking if there is a X to it, it’s from FIORI, if not it was SBWP.
The FIORI Send mail action:
The SBWP Send mail action:
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 (you can find out more about the process here):
Placed my Workflow ID and step ID on the filter:
So now let’s implement the method:
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:
Do you want to see it working? Check it out: DEMO Video.
Regards.

Nenhum comentário:

Postar um comentário