How Can I Query a List of Work Items Based on Process Template Name?

Applies To

Objective

To query a list of work items based on Process Template Name.

Summary

API such as QueryWorkList and QueryWorkListEx can be used to query a list of Work Items based on the process template name even though the WF_MANUAL_WORKITEMS table does not have a column for Process Template name (which is kept in a separate table).

Resolution

The following is an example of query a list of work items with a specific process template name.

string where = "";
SQLExprBuilder eb = SQLExprBuilder.GetBuilder( Global.DataBaseVendor );
if
( criteria.processTemplateName != null && criteria.processTemplateName.Length > 0 )
{
// To query the work item list belong to the specified process template name
if ( where.Length > 0 ) where += " and ";
where += eb.GetExpr("WF_PROC_DEFS.DEF_NAME", Constants.EQ, criteria.processTemplateName );
}
wks = api.QueryWorkListEx( where );

OR

public WFManualWorkItem[] GetProcessInstanceWorkItems( 
   string ProcessInstanceID )
        {
           string _searchClause = "";
try
        {
           if ( ProcessInstanceID.Length > 0 )
                    _searchClause += "WF_PROC_DEFS.DEF_NAME = '" + ProcessTemplateName + "'";

WFManualWorkItem[] wks = api.QueryWorkListEx( _searchClause );
                return wks;
           }
            catch ( Exception e )
            {
              throw new Exception( "Error with GetProcessInstanceWorkItems", e );
            }
        }