Thursday, April 8, 2010

Update DataFields for K2 Blackpearl workflows

Hi,
Here I am going to discuss about the K2 .net 2003 and BlackPearl (BP) workflows DataFields those help in repairing the workflows those got into error state. As we all know DataFields in workflows plays a big role in carrying the transactional data that are useful for decision making in workflow activities, especially in deciding line rules (Off course in BP we have actions to decide lines rules).

When I started working BP workflows few months back, I observed that fixing BP error workflows is not that easy as compared to K2.net 2003. Usually in K2.Net 2003 we add some condition related to process Instance ID (ProcInstID) and repair the error. Even thought BP has provided that ability to do it from Visual studio, it is not that easy to repair them as BP workflows uses XOML internally and every time we repair this error it deploys a new version workflow ( we can see this in version window of workflows in workspace). I didn't like this as this is risky thing to do this. Finally I found some way using APIs and updated the DataFields and repaired the workflows by just updating the DataFields. It was so easy.
Here is the code:
protected Connection GetBPConnection()
{

SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder connectionString = new SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder();
//connectionString.Authenticate = true;
connectionString.Host = "localhost";
connectionString.Integrated = true;
connectionString.IsPrimaryLogin = true;
connectionString.Port = 5252;

Connection connection = new Connection();
connection.Open(txtServerName.Text, connectionString.ConnectionString);
return connection;
}

protected void UpdateBPFields(string strFieldName, string strOldValue, string strNewValue)
{
SourceCode.Workflow.Client.ProcessInstance objBPProcessInst;
using (Connection connection = GetBPConnection())
{
//Create process instance
objBPProcessInst = connection.OpenProcessInstance(Convert.ToInt32(txtProcInstID.Text));

foreach (DataField dField in objBPProcessInst.DataFields)
{
//Check which FataField you want to update
if (dField.Name == strFieldName)
{
dField.Value = strNewValue;
}

}
// Call Update Method to update the DatField value
objBPProcessInst.Update();

}
}

For this utility you need to know the ProcInstID workflow which is gone into error state. This is easy to get them, in error profiles each workflow error shows the ProcInstID in the gird, as below.


Even we can do the same thing for K2.Net 2003 workflows.

This process not only helps for Error Workflows but for Active workflows. Sometimes, we might need to update some DataFields to change some rules after workflow started. The same process can be applied for K2.Net 2003, but the name spaces will be different (K2ROM.dll). For active workflow you can get the process Instance ID from workspaces (when you keep the mouse on workflow “ViewFlow” button you can see the ProcInstID in status bar, for K2 and BP workflows).

For K2 Error workflows you can see the ProcInstID directly in Error profile like below.


Hope it helps!

1 comment:

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...