Skip to main content

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