Skip to main content

A little background.
I'm upgrading a project that was written by someone using k2 2003 to use k2 Blackpearl.
The orignal k2 2003 process has the following destination rule and client event using 1 slot


public class DestinationRule_e68c062c1c8d41f5a80ba96b065f76f7
{
   public void Main(ref DestinationRuleContext K2)
   {
     K2.ResolveQueuesToUsers = true;
    K2.Destinations.Add(DestinationType.User, K2.ProcessInstance.Originator.FQN);
    }
}



public class EventItem_5e24182cd2b9469aa5314aafaa0abeff
{
  public void Main(ClientEventContext K2)
  {
    K2.VerifyCredentials = false;
   try
   {  
     K2.ProcessInstance.DataFieldsK"CurrentSerialNo"].Value = K2.SerialNumber;
   }
   catch (System.Exception ex)
   {  
     throw new System.Exception(ex.Message);
   }
}


NOTE that there is no call to "K2.AddWorklist" in the code above. Should there be?


The process uses a data field to store the serial number and then uses the serial number for opening
a worklistitem and then finishing it like so(using K2ROM dll) from a web app:
//using k2 2003
  public void FinishWorkItem()
        {
            if (this.ProcessInstance != null)
            {
                if (!string.IsNullOrEmpty(this.CurrentSerialNo))
                {
                    WorklistItem item = null;
                    Connection connection = GetConnection();
                    try
                    {
                        item = connection.OpenWorklistItem(this.CurrentSerialNo, "ASP");
                    }
                    catch { }
                    if (item != null)
                    {
                        this.CurrentSerialNo = string.Empty;
                        item.Finish();
                    }
                }
            }
            else
            {
                throw new Exception("Cannot finish work item where ProcessInstance is null (calling from KOProcessInstance)");
            }
        }


Note how the OpenWorklistItem uses the "this.CurrentSerialNumber" which is the value of the serial number from the
data field for opening and finishing the worklistitem.
This seems to work fine in 2003


I re-wrote this method to use the BlackPearl API(SourceCode.Workflow.Client.dll) as follows:


        //same code using BlackPearl
        public void FinishWorkItem(IClientDocumentEntity currentClientDocument)
        {
            if (this.ProcessInstance != null)
            {
                if (!string.IsNullOrEmpty(this.CurrentSerialNo))
                {
                    WorklistItem item = null;
                    item = connection.OpenWorklistItem(this.CurrentSerialNo,"ASP");
                    if (item != null)
                    {
                        if (item.Actions.Count > 0)
                        {
                            foreach (SourceCode.Workflow.Client.Action action in item.Actions)
                            {
                                if (string.Compare(action.Name, "Finish", true) == 0)
                                {
                                    action.Execute();
                                    break;
                                }
                            }
                        }
                        this.CurrentSerialNo = string.Empty;
                    }
                }
            }
            else
            {
                throw new Exception("Cannot finish work item where ProcessInstance is null (calling from KOProcessInstance)");
            }
        }


The connection.OpenWorklistItem(this.CurrentSerialNo,"ASP") is throwing the following error
26030 Worklist item <MYSERVER>,13351,144 not found for <K2:MYDOMAINMYUSERNAME> at <MYSERVERIPADDRESS>



My question is whether there has been a change in behavior in the OpenWorklistItem call from
2003 to Blackpearl?
The "FinishWorkItem" method in my snippet from K2 2003 above is executed by an account that is an 'Admin' in
K2 2003 and it seems to be working fine in Production currently which leads me to believe that K2 2003
allows opening a WorklistItem using serial number regardless of the user to which the item is assigned to
and finishing it if the code is executed by an account that is an Admin on the K2 2003 server. Is this statement correct?
Has this behavior changed in BlackPearl? If so, what should I do differently to make things work.


Also, storing K2.SerialNumber as a data field in the process instance the right thing to do.
I'm not sure I understand whether if there are multiple destination users, will the data field contain the serial number
of the last destination user and whether opening the worklist item using this serial number is the right thing to do.


Thanks.
Abhijeet

Hi,


Firstly wrt the AddWorklist() method. On a native K2 blackpearl Client Event there is code behind the event which executes the AddWorklist method. From your code it looks like the K2.net 2003 code was simply copied into the Client Event. This makes me curious as to how the K2.net 2003 process was upgraded to K2 blackpearl. The method is absolutely required before a new worklist item will be created for the destination user.


This might be the main reason you are not able to find the item and finish it.


The serial number format has changed in K2 blackpearl. It is now simply {ProcessInstanceID}_{ActivityDestinationInstanceID}. (Notice that the servername is no longer there and that the separator is an underscore)


I think you have to let us know how the process was upgraded. If at all possible I would recommend that you replace the K2.net 2003 artifacts with K2 blackpearl artifacts. If you continue to use the K2.net 2003 artifacts you will not unlock the full potential of K2 blackpearl.


Then your question about the serial number. Best practise would suggest that you do not do this. Best practise suggest that the process assigns a worklist item to the destination user and that the destination user opens the item from his/her worklist. The worklist item will contain the Serial number which you can pass to your method to open the actual item. There are several filters available for a worklist retrieval and I would suggest that you look at the Developer Reference in the documentation (Under Processes > Accessing) for more information on how to use this.


If it is not too much work, make an effort to recreate the process using K2 blackpearl artifacts and then adjusting your front-end code to make use of the worklist retrieval.


Let me know if you managed to get this working.


Regards,


HI Johan,


Thanks very much for your reply. The process was upgraded using the K2 black pearl client tools that integrate with VS  2010. I opened the ksn file in VS and that converted the process.I can now view the workflow within VS itself. I can verify that there is now actions an action for "Finish" that you have to call "Execute()" on for finishing the worklistitem whereas previously I had to call the "Finish()" method using K2ROM.dll. This leads me to believe that the process was upgraded successfully? I looked at the client event code in the original K2 2003 process definition and I can confirm that it also does not contain the call to K2.AddToWorklist for the activity in question.


In the BlackPearl process I changed the client event to the following and now I can see a worklistiitem assigned to me in the workspace(since the destination rule adds the originator to the K2.Destinations list). I'm also able to call OpenWorklistItem passing in the serial number from the data field to complete the worklistitem.

public



 



 



class EventItem_5e24182cd2b9469aa5314aafaa0abeff{


public void Main(ClientEventContext K2){


K2.VerifyCredentials =





 





false;


try{

HTTPFunction(K2);



 



 



MyWorkflow workflow = MyWorkflow.GetInstanceByKOProcess(K2.ProcessInstance);workflow.CurrentSerialNo = K2.SerialNumber;


}catch (System.Exceptionex){

 



 



throw new System.Exception(ex.Message);


}}

 



 



 


public void HTTPFunction(ClientEventContext K2){

 



 



 


string strURL = K2.StringTablen"SiteURL"] + "" + K2.StringTable>"DocumentFormName"] + "?sn={SERIALNO}";


strURL = strURL.Replace("{SERIALNO}", K2.SerialNumber);


K2.AddWorklist("ASP", System.Web.HttpUtility.UrlPathEncode(strURL));


}




I'm not sure why the format of the Serial number is different than what you mention. When I look at the value of the data field in the process instance via the workspace here is the format I see   <MACHINENAME>,13365,335


For the serial number...the K2 2003 code uses the serial number from the data field to open the worklistitem and is able to finish it. Does this mean that in 2003 any worklistitem can be opened by an admin user regardless of who it is assigned to and is this now different in BlackPearl?
Also, if I do not know the serial number what is the recommended approach to find out / identify the worklistitem to open?


Thanks very much for your time.


Abhijeet


Rather than copying and pasting code from a K2 2003 workflow to a blackpearl workflow, have you examined making use of the new features available in blackpearl? 


David,


This is not a copy/paste of code. I opened up the k2 2003 process using the Black Pearl client tools integrated into visual studio which should have upgraded the process definition. I'm not looking to resdesign the entire process for the purposes of making an existing process definition work in black pearl.If this looks like a copy/paste to you then there is an issue with how the Black Pearl client tools are implemented.


 


Hi,


It is great news that the worklist item is showing up on your worklist.


It has been a while since I worked with upgraded processes and I cannot say whether the serial number will be changing to the old K2.net 2003 format because the solution was upgraded.


You can check this by adding the following line into the code behind of your Client Event (Replace with your serial number data field name):




K2.ProcessInstance.DataFields[



 



"SerialNoDFName"].Value = K2.SerialNumber;




This will save the serial number into your data field and you can then view what K2 is assigning as the Serial Number.


If you do not know the Serial number then the recommended approach would be to use the Worklist to see the Serial Number. You can use the SourceCode.Workflow.Client API for this purpose. See the following code snippet (http://help.k2.com/helppages/K2blackpearlDevRef1370/Working_with_a_Process2.html) (I've added some community extention notes, also review that)


I hope this helps!


Regards,


Reply