Skip to Content

What I want in my rule resolution:

1) One-stop shopping for defining all the business users that are in charge of monitoring agents for their workflows.

2) I don’t want my workflow instances to fail when an agent cannot be found.   I would rather the work item be directed to a business user administrator.  This business user can find and forward to the correct agent and then modify the agent rules.

3) I want a message on the work item that states why the business admin has received the work item. “You have received this work item because no agent could be found.  Please forward this work item to the appropriate user and correct the agent rules.”

I’ve created a rule with responsibilities to hold all my business user administrators.   Notice I’m using priorities so that if a particular workflow is not set up in the rule it will default to the main workflow administrator.    For every workflow task that uses this method of directing work items to a particular admin, I simply add a new responsibility to the rule and assign an administrator.

WF Admin Rule.png

The rule has only one item in the container, this will be the workflow definition that will be passed to the rule so the appropriate administrator can be found.   You can use the task number or the workflow definition number.   I generally use the workflow definition number so if there are multiple tasks that require agents in the same workflow I can just set this up once.  Obviously if you have different administrators for different tasks you will need to work at the task level.

Rule Container.png


I add this rule to my workflow task as the default rule.   The default rule will only be used if the responsible users defined in the workflow come up empty AND if a rule is used to find the responsible users the rule must not have “Terminate If Rule Resolution Without Result” checked.   Notice the binding where I insert the workflow definition number.

Default Rule.png

I have noticed that the default rule is underutilized and most workflow tasks can be updated to use this method of directing work items to an administrator.


But I still want a message to be sent to the administrator if this default role is used.   I did this by adding a program exit to the workflow definition for this task. The exit will determine which rule was used to find agents, either the rule defined in the workflow or the default rule defined in the task and it will load a new container element into the task, “Agent Status”.   In the long task description of the task, the container element “Agent Status” will be read and an appropriate message will be displayed based on the contents.

program exit.png

CLASS zcl_wf_determine_rule_used DEFINITION

   PUBLIC

   FINAL

   CREATE PUBLIC .

   PUBLIC SECTION.

     INTERFACES if_swf_ifs_workitem_exit .

   PROTECTED SECTION.

   PRIVATE SECTION.

ENDCLASS.

CLASS ZCL_WF_DETERMINE_RULE_USED IMPLEMENTATION.

* <SIGNATURE>—————————————————————————————+

* | Instance Public Method ZCL_WF_DETERMINE_RULE_USED->IF_SWF_IFS_WORKITEM_EXIT~EVENT_RAISED

* +————————————————————————————————-+

* | [—>] IM_EVENT_NAME                  TYPE        SWW_EVTTYP

* | [—>] IM_WORKITEM_CONTEXT            TYPE REF TO IF_WAPI_WORKITEM_CONTEXT

* | [!CX!] CX_SWF_IFS_WORKITEM_EXIT_ERROR

* +————————————————————————————–</SIGNATURE>

   METHOD if_swf_ifs_workitem_exit~event_raised .

     DATA: ls_wi_header    TYPE swr_wihdr,

           lo_wi_container TYPE REF TO if_swf_ifs_parameter_container,

           lv_return       TYPE sysubrc,

           lo_rule         TYPE REF TO if_wapi_routing_context,

           lv_wf_task_id   TYPE v_sflow_rowfd_id, “string,

           lv_wf_version   TYPE swd_versio,

           lv_wf_rule      TYPE v_sflow_roexpression,

           lv_rule_used    TYPE hrobjec_14.

     CONSTANTS:

       c_agent_found TYPE char15 VALUE ‘AGENT FOUND’,

       c_sent_admin  TYPE char15 VALUE ‘SENT TO ADMIN’.

***********************************************************************

*   Process ‘After_rule_exec’ event

***********************************************************************

     IF im_event_name = swfco_event_after_rule_exec.

       TRY.

*         Get the Rule Context; what is returned is either the result from

*         the rule defined in the workflow, if no one is found,

*         the dafault rule defined in the task is returned.

           lo_rule = im_workitem_context->get_rule_context( ).

           lv_rule_used = lo_rule->get_rule_id( ).

*         Get the Workitem Information

           ls_wi_header = im_workitem_context->get_header( ).

           lv_wf_task_id = im_workitem_context->get_workflow_task_id( ).

           lv_wf_version = im_workitem_context->get_workflow_version( ).

*         Read the workflow definition to see if the workflow role compares

*         to the one that the workflow instance used.

           SELECT SINGLE expression FROM v_sflow_ro

                   INTO lv_wf_rule

                  WHERE  wfd_id   = lv_wf_task_id

                    AND  version  = lv_wf_version

                    AND  nodeid   = ls_wi_headerdef_guid+29(10).

*         Get Workitem Container

           lo_wi_container = im_workitem_context->get_wi_container( ).

*         Determine which rule was read, the default or the workflow rule.

*         If the default rule is used then update the workitem container so that

*         the long text description will include a note to the administrator.

           IF lv_rule_used = lv_wf_rule.

             CALL METHOD lo_wi_container->set

               EXPORTING

                 name       = ‘AgentStatus’

                 value      = c_agent_found

               IMPORTING

                 returncode = lv_return.

           ELSE.

             CALL METHOD lo_wi_container->set

               EXPORTING

                 name       = ‘AgentStatus’

                 value      = c_sent_admin

               IMPORTING

                 returncode = lv_return.

           ENDIF.

         CATCH cx_root.

           “Add error logic

       ENDTRY.

     ENDIF.

   ENDMETHOD.

ENDCLASS.

Now to show an example, below is how the workflow is defined for the task.   I using Rule 99900002 which as you can see does not have any one defined in the responsibility.   This rule will fail and the default rule will be used because when I defined the rule I told it to not terminate if no agent is found.

Rule set to fail.png

When I execute the workflow here is how the log looks.  Notice the container element AgentStatus indicates that the work item was sent to an administrator.

WF Log Before.png

This is what the administrator sees when they execute the work item:

workitem before.png

The workflow administrator that received the work item will now go update rule 99900001 to include Laura as the agent.

Rule Corrected.png

Now the administrator will re-run the agent rules.

execute agent rules.png

Now we can see that the agent was correctly set to Laura and the container element was updated to show the correct message.   This means that Laura will not have to see the ugly agent determination failure message when she works her work item.

workitem after.png

Depending on the comfort-level of your business users in the workflow log, they may want to execute the agent rules or they may just want to forward the work item to the appropriate user and then go clean up the agent rules.    The only problem with forwarding the work item is that the “Notice of Agent failure” message will not be removed as it will be if the rules are re-executed.

and yes…this may be a lot of trouble to go to when you can just set the work items to fail if no agent is found.   I just prefer this no-error method.

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

  1. Mike Pokraka

    Yet another great blog!

    FWIW, another technique I’ve used is local workflows. Works well in HR: An empty position will go up to the manager and at the same time trigger a local or global maintenance workflow.

    (0) 

Leave a Reply