Wednesday, March 2, 2011

Find WorkListItems with Worklist Criteria Filter in K2 Blackpearl

While working for an utility to redirect the tasks with some custom functionality I had to search for an option to bring the WorklistItems (tasks) based on some criteria (like Folio or Title) using LIKE operator with K2 API classes WorkflowCriteria and WorkflowCriteriaFilter, but it didn’t work. Googled with some keywords and found few articles, but I could not see any simple solution from them. So did some trials on search criteria on my own finally I could figure out that if we use percentile (%) symbols with LIKE operator it works perfectly. I didn't expect this as the APIs itself should take care (as per my understanding) of this when we use LIKE operator in Criteria classes. Anyway, it is working fine for me. I thought my findings may help some folks so posted that piece of code here.


 //Create a connection string with Integrated mode
    SCConnectionStringBuilder connectionString = new SCConnectionStringBuilder();
        connectionString.Authenticate = true;
        connectionString.Host = "ServerName";
        connectionString.Integrated = true;
        connectionString.IsPrimaryLogin = true;
        connectionString.Port = 5555;

        WorkflowManagementServer workflowServer = new WorkflowManagementServer();
        try
        {
            //Create a connection
            workflowServer.CreateConnection();
            workflowServer.Connection.Open(connectionString.ToString());

            WorklistCriteriaFilter filter = new WorklistCriteriaFilter();
            // Without % symbols it won't bring any data. It is important to add
   filter.AddRegularFilter(WorklistFields.Folio, Comparison.Like, "%srinitest%");
        
WorklistItems listItems = workflowServer.GetWorklistItems(filter);
            foreach (WorklistItem item in listItems)
            {
                //Add a row  to table to show it on form
   //AddRow(item.ProcInstID.ToString(),item.Folio,item.ActivityName,     item.EventName, item.Destination, item.ProcName);

            }
        }
        catch (Exception ex)
        {
            //Handle Exception here
        }
        finally
        {
         if (workflowServer != null && workflowServer.Connection != null)
            {
                //Dispose the connection saftely
                workflowServer.Connection.Dispose();
            }
        }

You can also find the code here Download

     Hope it helps!

Access to XMLHttpRequest at 'from origin has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https. .net core angular

Issue: The angular application was getting error from API that the origin has been blocked by CORS policy. Solution: Make sure that the...