Issue with Managment API and Filtering by Serial Number

  • 27 April 2010
  • 2 replies
  • 3 views

Badge +3

I'm trying to use the Management API to find a worklist item.  Our existing code based on a K2 sample works but is slow when there are a lot of processes.  I'm trying to find a worklistitem by serial number (i.e. 879_47).  The more efficient filter approach never brings back my result. 


Any ideas on what's wrong?


 // this works but is inefficient because it brings back everything and loops:


SourceCode.Workflow.Management.WorklistItems wl = cnnWMS.GetWorklistItems("", "", "", "", "", "", "");
                    foreach (SourceCode.Workflow.Management.WorklistItem wi in wl)
                    {
                        if (wi.ProcInstID + "_" + wi.ActInstDestID == serialNumber)
                        {
                            managedWorklistItem = wi;
                            break;
                        }
                    }


 


 


// This doesn't work, always returning null even though I know the work item exists.  This would be more efficient.  What's wrong???


 WorklistCriteria criteria = new WorklistCriteria();
                    criteria.AddFilterField(WCField.SerialNumber, WCCompare.Equal, serialNumber);
                    SourceCode.Workflow.Management.WorklistItems wl = cnnWMS.GetWorklistItems(criteria);
                    if (wl != null)
                    {
                        foreach (SourceCode.Workflow.Management.WorklistItem wi in wl)
                        {
                            if (wi.ProcInstID + "_" + wi.ActInstDestID == serialNumber)
                            {
                                managedWorklistItem = wi;
                                break;
                            }
                        }
                    }


2 replies

Badge +3

I'm pretty convinced that using WorklistCriteria never calls the database and does nothing.  So I tried the WorklistCriteriaFilter.  I've been able to get better performance with the following code.  However I cheated and ran a sql trace to find the constructed sql running and fixed the code as needed.  It isn't clean because I know the column names and table aliases in the query.  Still looking for cleaner help. 


WorklistCriteriaFilter criteria = new WorklistCriteriaFilter();
RegularFilter rfPID = new RegularFilter();
RegularFilter rfActID = new RegularFilter();
// why doesn't setting this prevent me from knowing alias?  Are there constants or enums to use?
//rfPID.TableName = "K2Server.dbo._ProcInst";
rfPID.ColumnName = "PI.ID";
rfPID.ParameterValue = serialNumber.Substring(0, serialNumber.IndexOf('_'));
rfPID.DbType = DbType.Int32;
rfPID.Comparison = Comparison.Equals;
rfPID.ParameterName = "@ICE_ProcInstID";
criteria.FilterCollection.Add(rfPID);


rfActID.Condition = RegularFilter.FilterCondition.AND;
// why doesn't setting this prevent me from knowing alias?  Are there constants or enums to use?
//rfActID.TableName = "K2Server.dbo._WorklistHeader";
rfActID.ColumnName = "WLH.ActInstDestID";
rfActID.ParameterValue = serialNumber.Substring(serialNumber.IndexOf('_') + 1);
rfActID.Comparison = Comparison.Equals;
rfActID.ParameterName = "@ICE_ActInstID";
rfActID.DbType = DbType.Int32;
criteria.FilterCollection.Add(rfActID);


SourceCode.Workflow.Management.WorklistItems wl = cnnWMS.GetWorklistItems(criteria);


 

Badge +8

SourceCode.Workflow.Management.WorklistItems wl = cnnWMS.GetWorklistItems(criteria);


This does not return anything, i opened a ticket with k2 guys last year and that's the answer i got. There are workarounds available but they are not really clean.


 

Reply