Exploring SourceCode.Workflow.Management  GetWorkListItems method. (Worklist Criteria Filter)

Capture

This Post will explain you how to retrieve K2Worklist using SourceCode.Workflow.Management GetWorkListItems method and its Worklist Criteria Filter, using C# assembly.

We already know that K2 have provided us 2 assemblies as mentioned below, which we can use to retrieve Worklist items.

  • SourceCode.Workflow.Management
  • SourceCode.Workflow.Client.

But the difference between them is, using  SourceCode.Workflow.Management  you can get complete worklist irrespective of user whereas using SourceCode.Workflow.Client  you can’t as the latter gives the worklist of only a specific user under which the code is being run. i.e. Now if you are running the code under my credentials domain\Vijay then you will get the worklist of only this user domain\Vijay.

Now let’s see how we use this  Workflow.Management Assembly.

Step 1: Add a new Class library project using Visual Studio, give your project & class file a name and you need to add reference of below 2 assemblies to the project. You can find these assemblies in ~drive/K2Blackpearl/bin folder

using SourceCode.Hosting.Client.BaseAPI;
using SourceCode.Workflow.Management;

**Hosting.Client.BaseAPI is part of SourceCode.HostClientAPI assembly

Step 2: Create ConnectionBuilderString as below.

SCConnectionStringBuilder connectionString = 
                      new SCConnectionStringBuilder();
connectionString.Authenticate = true;
connectionString.Host = denallix;//Server Name Here
connectionString.Integrated = true;
connectionString.IsPrimaryLogin = true;
connectionString.Port = 5555;

Step 3: Create WorkflowManagementServer object and open the Connection

WorkflowManagementServer workflowServer = new WorkflowManagementServer();
workflowServer.CreateConnection();       
workflowServer.Connection.Open(Convert.ToString(connectionString));

Step 4: Now use workflowserver object to call get complete WorkList

WorklistItems K2WorkListItems = workflowServer.GetWorklistItems(
    string.Empty, string.Empty,string.Empty, string.Empty, string.Empty, 
    string.Empty, string.Empty);

Step 5: Don’t forget to close the connection

 workflowServer.Connection.Close();

That’s it. Pretty Simple and fast right. Yes it is!! Now just add a console project to same above solution and call this method to debug and test this method.

Now let’s explore the options available in workflowServer.GetWorklistItems.              K2 has provided total 6 overloaded methods as below.

Option 1:

public WorklistItems GetWorklistItems(WorklistCriteria wl);

Option 2:

public WorklistItems GetWorklistItems(WorklistCriteriaFilter filter);

Option 3:

public WorklistItems GetWorklistItems(string destination, 
           string processName, string activityName, string eventName, 
           string folio, string fromDate, string toDate);

Option 4:

public WorklistItems GetWorklistItems(DateTime fromDate, 
              DateTime toDate, string destination, string processName, 
              string activityName, string eventName, string folio);

Option 5:

public WorklistItems GetWorklistItems(DateTime fromDate, 
             DateTime toDate, string destination, string processName, 
             string activityName, string eventName, string folio, 
             int start, int count, out int recordCount);

 

Option 6:

public WorklistItems GetWorklistItems(List<DateTime> fromDate, 
             List<DateTime> toDate, List<string> destination, 
             List<string> destinationCoparison, 
             List<string> destinationCondition, 
             List<string> processName, List<string> processNameComparison, 
             List<string> processNameCondition, List<string> activityName, 
             List<string> activityNameComparison, 
             List<string> activityNameCondition, 
             List<string> eventName, List<string> eventNameComparison, 
             List<string> eventNameCondition, List<string> folio, 
             List<string> folioComparison, List<string> folioCondition, 
             string StartIndex, string PageSize);

 

Out of above, option 1, 5, 6 are going to be removed soon so we shall ignore them and see how we can use the remaining options available.

Using Option 2:

public WorklistItems GetWorklistItems(WorklistCriteriaFilter filter);

To use this option we need to pass an object of type WorklistCriterialFilter which is available in assembly SourceCode.Workflow.Management.Criteria, let’s see how we can create and use this filter

In namespaces section add

using WMC = SourceCode.Workflow.Management.Criteria;

Now in the method you can use conditions as below

  • Filter for Folio = 1234
WMC.WorklistCriteriaFilter WLC = new WMC.WorklistCriteriaFilter();
WLC.AddRegularFilter(WorklistFields.Folio, WMC.Comparison.Equals, "1234");
WorklistItems K2WorkListItems = workflowServer.GetWorklistItems(WLC);
  • Filter for items where Folio contains word approval
WLC.AddRegularFilter(WorklistFields.Folio, 
                     WMC.Comparison.like, "%approval%");
  • Filter for items where ProcessName = POC.WKF.StudentsAdmission
WLC.AddRegularFilter(WorklistFields.ProcessFullName, 
                   WMC.Comparison.Equals, "POC.WKF.StudentsAdmission");
*ProcessName should be FullName of process with path.
  • Filter for items where ProcessName = WKF.StudentsAdmission AND Folio contains word approval
WLC.AddRegularFilter(WorklistFields.ProcessFullName, 
                     WMC.Comparison.Equals, "POC.WKF.StudentsAdmission"); 

WLC.AddRegularFilter(WorklistFields.Folio, WMC.Comparison.Like, 
                     "%approval%", WMC.RegularFilter.FilterCondition.AND);

 

  • Filter for items where ProcessName = WKF.StudentsAdmission OR Folio contains word approval
WLC.AddRegularFilter(WorklistFields.ProcessFullName, WMC.Comparison.Equals,
                     "POC.WKF.StudentsAdmission");           

WLC.AddRegularFilter(WorklistFields.Folio, WMC.Comparison.Like, 
                     "%approval%", WMC.RegularFilter.FilterCondition.OR);

 

These are some of the various conditions that you can try with WorklistCriteriaFilter.

Using Option 3 & 4:

                Both of these options are self-explanatory. You just have to pass the respective parameters for applying those filters.

  • Complete Worklist
WorklistItems K2WorkListItems = 
             workflowServer.GetWorklistItems(string.Empty, string.Empty, 
             string.Empty, string.Empty, string.Empty, string.Empty, 
             string.Empty);

 

  • Worklist for a Process (POC.WKF.StudentsAdmission)
WorklistItems K2WorkListItems = 
               workflowServer.GetWorklistItems(string.Empty, 
              "POC.WKF.StudentsAdmission", string.Empty, string.Empty, 
              string.Empty, string.Empty, string.Empty);

 

Now you can try rest of the options 🙂

I’ll create another post explaining the API SourceCode.Workflow.Client.

Handling Complex Objects in K2 SmartObjects

Deserializing Complex Objects in SmartObjects

java-serialization.png

This post is in continuation to my previous post K2 Integration with REST Api Services where I’ve created an SMO for a REST Api. As api’s return you serialized response, we need to further deserialize them using the Deserialize methods of that particular type/object.

Now if you see the result in below screen shot which is the result of WeatherAPI, it is providing a Serialized objects for Clouds, Coord, Main, Sys. Now to get the individual properties of the above mentioned serialized types/objects, we need to further deserialize them. Lets see how we can do.

SMOResults.jpg

Now the SMO which we have created in last post needs to be modified using K2 Designer. Select the method from service instance (Here it is GetWeatherbyCityName) and map the properties as shown in below screen shots.

ServiceInstance.jpg

MainMethodMapping.jpg

Now if you see the mapped properties in above screen shot, Clouds is mapped to a memo property Clouds (Clouds) which is the serialized result from api. Once the method is created click add and select Deserialize method of clouds from service instance as shown below.

CloudsDesrialize.jpg

Now the Deserialize method takes the serialized value as input and returns the individual properties of Clouds type. You need to map the serialized value which we got from above method as input and map the individual return properties to SMO properties (Here the property is ALL).

DeserializeClouds.jpg

Now similar to above add deserialize methods of other class types (Coord, Main..) and map their respective properties.

AllMethods

Now once you finish,  it should like below.

Method.jpg

That’s it. Click Finish and execute the SMO to see the individual properties as below

 

Results

CloudsALL is the deserialized value from Clouds Object, Similarly CoordinatesLatitude, CoordinatesLongitude are the desreialized values from Coord object, similarly Main Object Values you can see there.

That’s it. This is how we can Deserialize complex objects.

Here we have seen only single level of complexity which means for every weather result object, we get only one cloud object, one Coord object and so on. But there could be cases of result with multi-level complexity which means for every single weather result object there could be multiple cloud objects or multiple Coord objects and so on. In that case we may not be able to deserialize as we did above. We need to create separate methods for each object like GetCloudsbyCityName, GetCoordbyCityName, GetMainValuesbyCityName and handle the methods in same way as we did above.

Also in some cases, Api methods takes serialized objects as an input values, in that case we need to use the serialize method of that objects first which returns us the serialized value and then we need to pass this serialized value to the main method (just opposite to the way we did above).

This is how we can handle complex objects in K2 Smartobjects.

 

Bagi2info.com

Tips dan Trik Komputer, Tutorial Pemrograman, SQL, PHP, React Native - Expo

Mohamed Ashiq Faleel

Its time to think about Microsoft 365

Common Man Tips for Power Platform, Dynamics CRM,Azure

Venkata Subbarao Polisetty - Microsoft MVP,C# Corner MVP

James K2 Blog

Tips and Tricks about K2 workflow software

the BPM freak !!

"The illiterate of the 21st century will not be those who cannot read and write, but those who cannot learn, unlearn, and relearn" – Alvin Toffle

Start Rule

Learning K2 blackpearl and K2 Five

K2Ranger

Do K2 like a BOSS!!

Maverick

discover your own way and lead the world... with Divya Raj

jeylabs

Work Intelligently

Chasing Time - Mobile Gaming Photography Tips Tricks

#iamtheiosphotographer Pro Mobile Game Reviews, Tips, Tri

Jozsef Torsan

Founder & Software Engineer - Creator of the Bookmark Ninja Online Bookmark Manager

GreenEggs on K2

Saving the world with K2