In this blog post we will discuss K2 BlackPearl Mangement worklist webpart customization.
K2 offers Management Work list webpart and Work list webpart for managing work lists. However, there are situations when the webparts need to be customized to meet additional business requirements. Recall that the out of box K2 Management Worklist web part requires the user to have admin rights on the process and presents all process instances of that process running in the system without providing any filtering functionality?
Disassembling the appropriate K2 assemblies and inspecting the source code of ManagementWorklistWebPart class, we can see that the bulk of the processing to fetch the data to be displayed happens in the LoadWPData() method and a fair bit of the processing is performed using classes declared internal to the assembly. The end result of the processing is the creation of a DataTable object containing data for all process instances and assigned to a class member. There are two different options to enhance this class:
- Option 1 – Override this method in a class derived from the out-of-box ManagementWorklistWebPart class.
- Option 2 – Invoke the base class’s LoadWPData() method in the derived class followed by applying the desired filter on the created DataSet.
Below is an implementation of Option 2. To prune down the unfiltered data set, it’s joined with a data set containing only rows of interest. This 2nd data set can be created in any desirable way (e.g. using filter parameters exposed as web part properties). In our implementation it’s created using a process SmartObject’s GetList() method, which is then filtered based on the Project ID stored as Process Data Field in the current process instance. The joined data set is stored in the class member _dataTable, from where it’s rendered using other methods in the base class.
public override void LoadWPData() { try { // Create the unfiltered data set using base K2 class base.LoadWPData(); // Create the filtered data set using DHF SmartObject and join with Unfiltered set to remove unwanted rows DHFProcessData dhf = new DHFProcessData(); dhf.Status = 1; if (bFilteringInEffect) { DataTable dt = dhf.GetList(); IEnumerable<DataRow> query = from processInst1 in _dataTable.AsEnumerable() join processInst2 in dt.AsEnumerable() on processInst1.Field<string>("ProcInstId") equals processInst2.Field<string>("ProcessInstanceId") select processInst1; DataTable boundTable = query.CopyToDataTable(); this._dataTable = boundTable; } } catch (Exception ex) { this._errorList.Add(ex.Message); } }