Opening a process instance from K2, need help plzz

  • 27 April 2007
  • 6 replies
  • 8 views

Badge +7
I m working with k2Rom to create smartforms

I would like to ask how to open a K2 process instance dynamically without putting the id statically

Proc = conK2.OpenProcessInstance (?)

6 replies

Badge +3
Hi,


What's your overall goal?

Where do you intend to get the ID from, and where are you planning on running the K2ROM code from?

Regards,
Ashley
Badge +7
Thanks ashley but it works

This is the solution :
I have two forms :

the first one will be filled by the user and the other is the manager approval

The first contain a plain button wich contain:



Dim conK2 As New K2ROM.Connection
Dim procinst As K2ROM.ProcessInstance
Dim strCon As String
strCon = "[;];Authentication=Windows;Domain=k2mega.local;User=administrator;Password=k2pass"
conK2.Open("k2megasrv", strCon)
procinst = conK2.CreateProcessInstance("SalesTravel Request")
procinst.Folio = "myProcess"
procinst.DataFields("FullName").Value = txtFullName.Text
procinst.DataFields("email").Value = lbl_Email.Text
procinst.DataFields("Motivation").Value = lbl_Motivation.Text
procinst.DataFields("DepartureDate").Value = lbl_DepartureDat.Text
procinst.DataFields("ReturnDate").Value = lbl_ReturnDate.Text
procinst.DataFields("TravelRe").Value = Trav.SelectedValue.ToString
procinst.DataFields("Dest").Value = Dest.SelectedValue.ToString
conK2.StartProcessInstance(procinst)
conK2.Close()

and the second contain a finish button :


on form load the code is :



strCon = "[;];Authentication=Windows;Domain=k2mega.local;User=Suzans;Password=k2pass"
conK2.Open("k2megasrv", strCon)
wklwork = conK2.OpenWorklist("ASP")
wkliwork = conK2.OpenWorklistItem(Request.QueryString("sn"), "ASP", True, True)
procinst = conK2.OpenProcessInstance(wkliwork.ProcessInstance.ID())
procinst.Folio = "myProcess"
txtFullName.Text = procinst.DataFields("FullName").Value

on the finish buton the code is :


wkliwork.ProcessInstance.DataFields("Approval").Value = ddlapp.SelectedValue.ToString

wkliwork.Update()
wkliwork.Finish()
conK2.Close()


These two forms are webformes worked with K2Rom to replace the smartforms

Please i need to know if i'm starting to think correctly or no
thanks a lot :)
Badge +11
Hi Melhem,

Yes, congrats, you're on the right track!!

Just one thing...
In your code:
wkliwork = conK2.OpenWorklistItem(Request.QueryString("sn"), "ASP", True, True) 
procinst = conK2.OpenProcessInstance(wkliwork.ProcessInstance.ID())
procinst.Folio = "myProcess"
txtFullName.Text = procinst.DataFields("FullName").Value

you must be aware of the fact that in order to Open a process instance like: procinst = conK2.OpenProcessInstance(wkliwork.ProcessInstance.ID()), the logged-in user will need to have 'Admin' rights on the process in K2.net Service Manager. The better way to access the process instance would be to go via the worklist item i.e.
wkliwork.ProcessInstance.Folio - to set the Folio and
wkliwork.ProcessInstance.DataFields("FullName").Value - to retrieve the datafield value. If the Folio value is not set correctly afterwards, just call a 'wkliwork.Update' or 'wkliwork.ProcessInstance.Update' to force the update.

Oh, sorry, another thing - since these pages will be used as a web front end, I presume you'll want to know who the user is. In this case you can discard the connection string info in the 'conK2.Open("k2megasrv", strCon)' call. If you just call 'conK2.Open("k2megasrv")', the logged-on user credentials will be sent to the K2.net Server. Just make sure that the user submitting the 'Plan' page have got 'Start' rights to the process.

HTH,
Ockert
Badge +7
Thanks Ockert a lot.
Badge +3
May I know what is the function of '[;]' in connection string?

i.e.
strCon = "[;];Authentication=Windows;Domain=k2mega.local;User=Suzans;Password=k2pass"

Can I omit it?
Badge +5
Hi,
It indicates what character is used as the delimeter. Therefore if you use the following connection string 'Bob' will be logged onto the k2 server.
'[$]$Authentication
=Windows$Domain=k2demo.local$User=bob$Password=k2pass'.
If you do not indicate what delimeter is used it will ignore the connection string and log on with the current user.

Regards
Gert

Reply