Skip to Content
Technical Articles

S/4HANA Flexible Workflows: Workflow Scenario Development and Configuration – Part 2

This blog is part 2 of blog. In previous blog, we have created the workflow scenario and defined the 2 user decision steps, one condition and did other required activities. In this blog, we will look at the run time callback class, workflow configuration and testing of workflow.

Run Time callback class

We specified this class under ‘Control’ tab of workflow scenario. We defined the class ZCL_CUSTUSER_RUNTIME_DATA as subclass of base class proposed by system. We can redefine various base class methods in this class as per need, but for our development, we are primarily interested in 2 methods:

Method which is called after completion of each activity – ~ AFTER_COMPLETION_CALLBACK

This method can be used to derive any intermediate information based on workflow context or current activity, handle different approval results from previous step etc. For example, we can derive some customizing information after a step based on run time field value.

It is not necessary to implement this method to make our workflow work. Framework can handle POSITIVE/ NEGATIVE outcomes by itself. I wanted to show its implementation as this could be a very useful method for intermediate calculations.

METHOD if_swf_flex_ifs_run_appl_step~after_completion_callback.

    DATA(step_execution_results) = io_current_activity->get_execution_results( ).

    TRY.
        DATA(approval_result) = step_execution_results[ 1 ]-nature.
      CATCH cx_sy_itab_line_not_found.
    ENDTRY.

    IF approval_result EQ 'POSITIVE'.
      ev_action = if_swf_flex_component=>c_action_continue.
    ELSEIF approval_result EQ 'NEGATIVE'. "Means it's rejected
      ev_action = if_swf_flex_component=>c_action_cancel.
    ENDIF.
  ENDMETHOD.

Method which is called at workflow completion –~ RESULT_CALLBACK

This method is important to implement as this is where we do the final update which should happen at the completion of workflow. In our case, it is to update the custom table.

METHOD if_swf_flex_ifs_run_appl~result_callback.

    DATA: ls_user_data TYPE zcustusermast.

    DATA(ls_result) = io_result->get_result( ).
    IF ls_result-nature = 'POSITIVE'.
      DATA(lr_wf_container) = io_context->get_workflow_container( ).
      TRY.
          lr_wf_container->get(
            EXPORTING
              name       =  'UserData'               " Name of the Component Whose Value Is to Be Read
            IMPORTING
              value      = ls_user_data ).                 " Copy of the Current Value of the Component
        CATCH cx_swf_cnt_elem_not_found.     " Name Entered Is Unknown
        CATCH cx_swf_cnt_elem_type_conflict. " Value Not Type Compatible to Current Parameter
        CATCH cx_swf_cnt_unit_type_conflict. " Unit Not Type Compatible to the Current Parameter
        CATCH cx_swf_cnt_container.          " Exception in the Container Service
      ENDTRY.

      IF ls_user_data IS NOT INITIAL.
        MODIFY zcustusermast FROM ls_user_data.
      ENDIF.

    ENDIF.

  ENDMETHOD.

Our Workflow Scenario development is complete now. Save and activate the scenario.

Workflow Configuration:

Once scenario is created, next activity is to define the workflow. This activity is primarily for business users, who can design the workflow without being concerned about the complexity that lies under. Ideally business users should be configuring the user-decision steps only while workflow scenario should handle rest of the process complexity.

Open fiori Application ‘Manage Workflows’ and choose your workflow scenario. In our case, it is ‘Custom User Master’:

Press ‘Add’ and enter ‘Name’ and properties like validity dates and description.

Under ‘PRECONDITIONS’, our Company ID precondition is shown:

As defined under ‘Conditions’ tab in Part 1 of blog series, precondition for company ID is available.

Add steps under ‘STEP SEQUENCE’:

Step 1: Type         – Validate the Data

( For the Type, you get a drop-down from the activities you defined in Part 1)

Recipient  – Workflow Initiator

Default recipients are shown from the ones already available under ‘Agents’ tab in Workflow Scenario. Since we haven’t created any agents there, we are offered the default ones here.

Same Company ID precondition is available here as well. Since, we have already configured it at header level, we won’t use it at step level.

We accept the default exception handling:

‘Name’ is the NEGATIVE outcome from the Activity we defined in Part 1.

Step 2: Type – Create the Table Records

Follow the similar steps as Step 1.

 

Both the workflow steps are created now:

Save and activate the workflow. If there are already existing workflows for your workflow scenario, make sure that order is such that your workflow is the first to trigger for given data.

Testing:

We create the data through our entry program. I execute the program with below data:

Transaction SBWP and I see the work item in my inbox

( Same work item should be available in ‘My inbox’ Fiori app as well and processing should happen the same way as it happens through SBWP ).

I approve the work item and now, I receive the second approval work item as well:

I approve this work item as well. Now, my records should get created in custom table:

Entries are created in custom database table:

I tested by creating a table entry with a company ID other than ‘1010’. As expected, no workflow instance was created.

I tested by rejecting one of the approvals. As expected, workflow was terminated, and no workflow instance was created.

 

I hope this simple workflow development has given you enough idea to develop a small prototype yourself. There are lot more possibilities in workflow scenarios, which I will explore and keep on sharing my learning as well. Looking forward to many other blogs in this space!

15 Comments
You must be Logged on to comment or reply to a post.
  • I cannot wait for your next blog on providing custom pre-conditions to standard workflow config in "Manage Workflow" app. That will solve a major demand from customers to be able to end workflows  (especially standard delivered) based on pre-conditions, without having to go through all possible approval levels.

     

    This is a great blog to help understand the over all Workflow Scenario concept and how it integrates with the Manage Workflow App!

     

    great going!

    • Thanks Modak. Custom pre-condition blog should be there in a week or two. But, for custom pre-conditions, there should be BAdIs provided by framework to create custom pre-conditions and evaluate them. Currently, it's possible for purchasing.

  • Hi Gaurav,

    Thanks for posting such a detailed and interesting post on creating the workflow S4 Hana. However could you please throw some on light on the process to attach business objects to the user Decision . Is it similar to previous process in SWDD or there is some change to it. ?

  • Thanks Gaurav Karkara,

    Am I right – you are developing the scenario with objects in the same system/client where you configure the Fiori App so you don’t need any ODATA services etc.?

    Or maybe odata services will not be required even it was two different systems?

    Thanks,

    Claus Lücking

    • Hi Claus,

      You are right.

      I see no option to generate any ODATA service during workflow development/configuration.I don't think it would be required.

      GK

  • Hello, I was following your blog. Nice write up. You say to just "Save and activate the scenario".

    I was having issues with the system saying the scenario was not active. Even though it very much said "Active". After an hour or so of debugging the workflow system. I discovered that it was looking for an entry marked active in table SWF_FLEX_SCACT. I also found there to be a view on top of it called V_SWF_FLEX_SCACT that had a table maintenance defined.  I simply added the Scenario there using SM30 and everything worked. This is on an S/4 1709 system. Wondering if something is wrong with our system or if this is a necessary step? There isn't much on google/SDN/OSS about that table/view.

    • This view is actually a customizing step at path: SAP NetWeaver -> Application Server -> Business Management -> SAP Business Workflow -> Flexible Workflow -> Scenario Activation

      You'll see the same table, and you need to maintain the active flag here.

  • Hi Gaurav,

    Thanks for the blog.

    I created a new Flex workflow scenario, activated it with activities, pre-conditions, rules etc. Maintained all the customizing I know, but in the manage workflows app in fiori, I still cannot see my scenario in the drop down. Even in the app Manage Workflow Scenarios, this one doesn't appear. Do you know where else I need to maintain an entry to make this scenario available in Fiori?

      • Yes, I managed finally.

        It was a weird reason. This customer has two separate clients in the dev system. One for actual development, and another one for the unit tests, which the (separate) fiori UI system is connected to.

        So after doing any customizing changes, we’ve to copy the client dependent ones with SCC1 from dev client to the UT client.

        In this case as well, I did SCC1 after I ‘activated’ the scenario in the ‘Scenario Activation’ customizing. But the problem is, when I created the new scenario in SWDD_SCENARIO, an entry got added to this customizing view automatically. So when I went to this customizing, and ‘checked’ the activation checkbox and saved, only that got addded to the customizing requesst, but the actual addition of the entry was missing. So when I did SCC1, the customizing view in the UT client never actually got this new entry of the scenario.

        So I had to manually add the transport entry from the customizing, and then did SCC1. Viola the scenario appeared in the dropdown!

        Just a stupid bug, I believe, in the SAP system, that it doesn’t add the customizing transport entry, when the scenario entry gets added to the SWF_FLEX_SCACT table.

  • Hi Gaurav,

     

    I created a workflow scenario in SWDD_SCENARIO, and activated the workflow scenario in Scenario Activation.

    The scenario is active and there are no errors, however, i am still not able to search/locate my workflow scenario in the Manage Workflow Application (I can see other work flow scenarios, other than my custom scenario).

    I debugged the underlying odata service SWF_FLEX_DEF_SRV for the root cause, and figured out that the entity set Get Scenarios is returning my WorkFlow Scenario, but still it is not visible in the App.

     

    Could you provide some pointers where to check?

     

    Thanks!

     

    /
    • You can also check if the scenario is active in tcode SWF_PROCESS_ADMIN. Make sure the Version 0000 is active for the new scenario you've created.

  • Hi Gaurav,

    Under the step sequence, when adding steps, how does the step conditions work exactly? Is there any documentation about them specifically? How're they different from the Pre-conditions?

  • Hello Gaurav,

    Thank you for this blog. This is really helpful to start with Flexible workflow.

    I followed the steps and created the workflow using SWDD_SCENARIO , while testing the same in SAP, am getting below error :

    Request you to Please help me as am not able to understand where is the gap.

    Have checked in /nSWF_PROCESS_ADMIN also, and workflow is being displayed as active.

     

    Would be really grateful if you could help me.

     

    Thank You,

    Ishani Goel

     

  • Hi Gaurav,

    Thanks for this wonderful blog. Its cleared most of my doubts.

    I have requirement to call my my custom Workflow Scenario with 'Verify General Journal Entry' app. I have developed my custom workflow scenario. Now I want to configure this with my app.

    Can you please help me here?

     

    Thanks,

    Avish Mittal