This topic applies only to the IBM Business Automation Workflow Advanced
configuration.

Example: Querying tasks in the ready state

Draft comment:
This topic only applies to BAW, and is located in the BAW repository. Last updated on 2025-03-13 12:15
This example shows how to use the query method to retrieve tasks that the logged-on user can work with.
John Smith wants to get a list of the tasks that have been assigned to him. For a user to be able to work on a task, the task must be in the ready state. The logged-on user must also have a potential owner work item for the task. The following code snippet shows the query method call for this query:
query( "DISTINCT TASK.TKIID", 
           "TASK.KIND IN ( TASK.KIND.KIND_HUMAN, TASK.KIND.KIND_PARTICIPATING ) 
             AND " +  
           "TASK.STATE = TASK.STATE.STATE_READY AND " +  
           "WORK_ITEM.REASON = WORK_ITEM.REASON.REASON_POTENTIAL_OWNER", 
            (String)null, (String)null, (Integer)null, (TimeZone)null )
The following actions are taken when the SQL SELECT statement is generated:
  • A condition for access control is added to the where clause. This example assumes that group work items are not enabled.
  • Constants, such as TASK.STATE.STATE_READY, are replaced by their numeric values.
  • A FROM clause and join conditions are added.
The following code snippet shows the SQL statement that is generated from the API query:
SELECT DISTINCT TASK.TKIID
   FROM   TASK TA, WORK_ITEM WI,  
   WHERE  WI.OBJECT_ID = TA.TKIID
   AND    TA.KIND IN ( 101, 105 )       
   AND    TA.STATE = 2   
   AND    WI.REASON = 1           
   AND  ( WI.OWNER_ID = 'JohnSmith' OR WI.OWNER_ID = null AND  WI.EVERYBODY = true )
     
To restrict the API query to tasks for a specific process, for example, sampleProcess, the query looks as follows:
query( "DISTINCT TASK.TKIID", 
           "PROCESS_TEMPLATE.NAME = 'sampleProcess' AND "+
           "TASK.KIND IN ( TASK.KIND.KIND_HUMAN, TASK.KIND.KIND_PARTICIPATING ) 
             AND " +  
           "TASK.STATE = TASK.STATE.STATE_READY AND " +  
           "WORK_ITEM.REASON = WORK_ITEM.REASON.REASON_POTENTIAL_OWNER", 
            (String)null, (String)null, (Integer)null, (TimeZone)null )