I have WF1 & WF2, and there is a running instance of WF2 that I want to change it's Folio from WF1, is this applicable? I found a SmartObject called ProcInst that returns the Process Instance data (folio, ID, etc.. ) but I don't know how to update it. I tried to create a server event but I couldn't use SourceCode.Workflow.Management the error message is Type or namespace could not be found, I couldn't add reference, I am using VS 2010.
Assuming this isn't a one off.Â
If WF1 is calling WF2 through an IPC event you can set the folio through the IPC wizard.Â
Otherwise you can update the WF2 folio through the workflow client API. The catch is you can't do it directly in WF1 as it can cause database problems. The way to do it is add your code in a dll and then call the dll from the workflow through a server event in WF1. You add references through the Process References on the process toolbar.
Here is some quick and dirty code which will change the folio. However, the account that executes it will need admin permissions on the process.
SourceCode.Hosting.Client.BaseAPI.
SCConnectionStringBuilder
connectionString =new SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder();
connectionString.Authenticate = tr
ue
;
connectionString.Host =
"localhost"
;
connectionString.Integrated =
true
;
connectionString.IsPrimaryLogin =
true ; "K2";
connectionString.Port = 5252;
connectionString.SecurityLabelName =
//the default label
Connection connection = new Connection();
try
{
//open connection to K2 server
connection.Open(
"localhost"
);
 ProcessInstance processInstance = connection.OpenProcessInstance(Convert .ToInt16(txtProcID.Text)); "new folio text";
processInstance.Folio =
processInstance.Update();
}
Â
Â
catch (Exception
ex)
{
Â
Console .WriteLine(ex.Message);
Â
Console
.ReadLine();
{
Â
// close the connection
connection.Close();
}
Thank you timkn for your fast reply.
To be more descriptive, my WF automates small Project Management system, each K2 instance reflects a Project, Project Names are unique, so are their Folios.
The case I am having here is I have a Maintenance (Editing) WF that can be triggered in the middle of the project (WF) that allows the user to change Project Data, which includes the project name, so the project has another running instance in another WF, that is why I need to rename the Folio after renaming the Project.
So WF1 is totally independent of WF2 they are not calling each other.
But what I understand from the code here is that I already have the ProcessInstance ID, I need to do this functionality (renaming Process Folio) either from a webservice completely by code, or completely by WF.
I prefer to use a webservice for the whole functionality, so is there a way to get the process instance ID by code, note that I maintain unique Folios.
Of course if you have a better Idea it would be great.
Thanks in advance.
To get the process instance ID you should be able to call the out of the box Process Instance smartobject from wf1 to get the process instance ID of wf2 using the folio of wf2 as a filter parameter since you said the folios are unique.
Although I haven't tried it you should be able to update the folio using the K2Services WS, WCF or Rest services documented in the K2 developer reference
http://help.k2.com/en/K2blackpearlDevRef4.6.4.aspx
Developer Reference > Services Reference > K2 Services > Web Services
Â
Hi Mohamed,
As you said both the workflows are independent. Then you dont have to rename the instance name.Â
Check this is my understanding..
There is a workflow running , and in the middle of the process you are calling another WF which has an ability to change the project name which is the folio of first WF...
If this is the case .. I have few QueryÂ
Do you want the folio of  process instances of both the workflows to be same ?
Â
At the end, I created these functions with reference to :
K2 Blackpearl Developers Reference
//using
SourceCode.Hosting.Client.BaseAPI;
       //using SourceCode.SmartObjects.Client;
       //using SourceCode.Workflow.Client;
       /// <summary>
       /// Returns K2 Process
Instance ID Using Process Instance Folio, Note we maintain unique Folios
       /// </summary>
       /// <param name="ProcessFolio">The Folio of the Process</param>
       /// <returns></returns>
       public intt]
GetProcessInstanceID(string ProcessFolio)
       {
           //Create Connection String
Â
           SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder
hostServerConnectionString = new
SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder();
          Â
hostServerConnectionString.Host = "localhost";
          Â
hostServerConnectionString.Port = 5555;
          Â
hostServerConnectionString.IsPrimaryLogin = true;
          Â
hostServerConnectionString.Integrated = true;
Â
           //Create SmartObject Client Server
Â
          Â
SourceCode.SmartObjects.Client.SmartObjectClientServer
serverName = new
SourceCode.SmartObjects.Client.SmartObjectClientServer();
          Â
serverName.CreateConnection();
          Â
serverName.Connection.Open(hostServerConnectionString.ToString());
Â
           try
           {
              Â
// Use Smart Object Name or GUID
              Â
//SourceCode.SmartObjects.Client.SmartObject
adUserSmartObject = soServer.GetSmartObject(new
Guid("dcf2ad39-e7a7-43ce-8141-0928353afb38"));
              Â
SourceCode.SmartObjects.Client.SmartObject
smartObject = serverName.GetSmartObject("Process_Instance");
              Â
//Do whatever you like with the
SmartObject/Connection
              Â
//List<SourceCode.SmartObjects.Client.SmartMethodBase>
ls = smartObject.AllMethods;
Â
              Â
// specify which method will be called
              Â
smartObject.MethodToExecute = "List";
Â
              Â
// specify input parameters for the method
              Â
smartObject.Properties "Folio"].Value
= ProcessFolio;
Â
              Â
// call the method
               //serverName.ExecuteScalar(smartObject);
              Â
// note: if a method of type 'list' was
specified, then the 'ExecuteList' method should be called
              Â
// serverName.ExecuteList(smartObject);
Â
              Â
SmartObjectList smoList =
serverName.ExecuteList(smartObject);
Â
              Â
bool isFound = false;
Â
              Â
int ] ProcessInstanceIDs = new intn2];
Â
              Â
// read the return properties of the
SmartObject
Â
              Â
for (int
i = 0; i < smoList.SmartObjectsList.Count; i++)
              Â
{
                  Â
if
(smoList.SmartObjectsList.Propertiesd"Folio"].Value
== ProcessFolio)
                  Â
{
                       ProcessInstanceIDs =
int.Parse(smoList.SmartObjectsList.Properties "ProcessInstanceID"].Value);
                       isFound = true;
                  Â
}
              Â
}
Â
              Â
if (isFound)
              Â
{
                  Â
return ProcessInstanceIDs;
              Â
}
              Â
else
              Â
{
                  Â
return null;
              Â
}
           }
           catch (Exception)
           {
              Â
throw;
           }
           finally
           {
              Â
serverName.Connection.Close();
           }
Â
       }
       public void
CheckAndRenameK2Folio(string projectName, string projectNewName)
       {
          Â
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;
          Â
connectionString.SecurityLabelName = "K2";
           //the default label
Â
          Â
SourceCode.Workflow.Client.Connection
connection = new SourceCode.Workflow.Client.Connection();
Â
           try
           {
              Â
//open connection to K2 server
              Â
connection.Open("localhost");
              Â
//create process instance
Â
              Â
SourceCode.Workflow.Client.ProcessInstance
processInstance = connection.OpenProcessInstance(375);
              Â
processInstance.Folio = "NEW NAME";
              Â
processInstance.Update();
           }
           catch (Exception
ex)
           {
              Â
Console.WriteLine(ex.Message);
              Â
Console.ReadLine();
           }
Â
           finally
           {
              Â
// close the connection
              Â
connection.Close();
           }
       }
Â
Â
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.