Serial Number retrieval from Server Side Event?

  • 23 September 2005
  • 14 replies
  • 13 views

Badge +1
I want to cancel a form already in the process. I don't know what the serial number is at that stage. How can i get the serial number using the folio so that i can set the status to Cancel and complete the process?

14 replies

Badge +11
Hi Tania,

What do you mean with: "I want to cancel a form already in the process"?
Is it a form which has already been completed by a user and you need to 'roll-back' the changes which were made by the user? OR is it a form waiting to be actioned by a user? In the former case, the Client event has already been completed and there will be no serial number available. In the latter case, the user can either submit the form without any changes or you can use 'GoTo' in K2.net Service Manager to send the process flow to the next Activity which will effectively expire the pending Client Event and Activity.

Do you want to achieve this from inside a process definition or from an external application?

Regards,
Ockert
Badge +1
Thanx for the reply. I think the GOTO would be sufficient enough in this case.
Badge +3
do you guys have any idea how to get the serial number of my client event in C#? i want my K2ROM to get that specific worklist item and force the next activity to work (by using GotoActivity method upon detection of that specific worklist item)

i let k2 generate the code and here it is:
Dim strURL as String
trURL = "http://localhost/testapprove/WebForm1.aspx?sn={SERIALNO}"
strURL = strURL.Replace("{SERIALNO}",K2.SerialNumber)
K2.AddWorklist("ASP",System.Web.HttpUtility.UrlPathEncode(strURL))


how do i know which string generates the random number after my server name in the worklist URL? i have to get that "random number" and append it to my:
SourceCode.K2ROM.WorklistItem WLItem = myConn.OpenWorklistItem("sn", "ASP");
Badge +11
The easiest method of obtaining a specific Worklist item would be to loop through all worklist items for a specific user and compare Process Instance Folios to get to the right item. The WorklistItem object has got a 'SerialNumber' property, but by the time you get to the correct Worklistitem, it's obviously too late for you to use it. I would use code similar to this:


//Open Connection
oK2Connection.Open(strK2Server);

//Get Worklist for current Logged on User
oWorkList = oK2Connection.OpenWorklist("ASP");

foreach(SourceCode.K2ROM.WorklistItem oWorkListItem in oWorkList)
{
if(oWorkListItem.ProcessInstance.Folio == strFolio)
{
oWorkListItem.GotoActivity("Declined", false); //Force the process to another Activity contained in the same Process
}
}


If your users have got a large amount of worklist items, consider using the WorklistCriteria object to narrow down the search. Please refer to help file for sample code.

Hope this helps,
Ockert
Badge +3
thanks ockert! it helped a lot! i made it like this:

;
myProc.Folio = strFolio;


then your same code: ...

if(myWorklistItem.ProcessInstance.Folio == strFolio)
{
myWorklistItem.GotoActivity("Approval", false);
}


question only: while i was reading through the PDF file of module 7 intro to k2rom, there is a property there called SerialNumber that goes:

mySerial = MyWorkItem.SerialNumber


i assume this will also return serial number?
cos the method i was trying to use before was:

SourceCode.K2ROM.WorklistItem myWorklistItem = K2ROMConnection.OpenWorklistItem("sn", "ASP");
myWorklistItem.GotoActivity("Approval");


then for testing purposes, i "hard-coded" the serial number like so:
SourceCode.K2ROM.WorklistItem myWorklistItem = K2ROMConnection.OpenWorklistItem("SERVERNAME,139,12", "ASP");
myWorklistItem.GotoActivity("Approval");


is that advisable or will that be a lot of work? will your suggested code also do the same thing that i'm trying to achieve? :D
Badge +11
Just a couple of concerns...

; 
myProc.Folio = strFolio;


It's fine to set the strFolio variable for comparison to be used in myWorklistItem.ProcessInstance.Folio but the myProc.Folio should have already been set when the process instance was initially planned.

True, there is a property: myWorklistItem.SerialNumber. The problem however is that in order to use code like: K2ROMConnection.OpenWorklistItem("sn", "ASP"), you're trying to open a Worklist item with a specific serial number but you haven't got access to the SerialNumber property yet. Only once it is open, you can access the property - kind of a chicken or egg problem.

It's fine to use hardcoded Serial Numbers, it should definitely work but obviously would not be a very generic solution as you would have to change the serial number each time you want to access a specific Worklist item.

The overloaded OpenWorklistItem("sn", "ASP") method is generally only used when you've already got a specific worklist item's serial number.

Hope this makes sense,
Ockert
Badge +3
icon-quote.gifOckert:
Just a couple of concerns...

It's fine to set the strFolio variable for comparison to be used in myWorklistItem.ProcessInstance.Folio but the myProc.Folio should have already been set when the process instance was initially planned.



I set the myProc.Folio before I called the StartProcessInstance method, after I called the CreateProcessInstance method. Is that ok? Cos if I don't set it, Process Folio in the workspace would just display my Process name. A whole list of indistuinguishable Process names, right?

Thanks for the enlightenment on the serial number issue. Now I get it. Thanks! I'll be using the first code you posted. :)
Badge +11
Correct...
That's exactly where you should set the Process Instance folio - in between CreateProcessInstance and StartProcessInstance.

Glad I could help,
Ockert
Badge +3
In connection with GotoActivity method, this will go to your specified activity, right? But then the line connecting to it will not be any color (neither red or green), right? How can I make that line green? Thanks in advance.
Badge +11
That is unfortunately one of the draw-backs of using GotoActivity method and exactly the reason why I don't like to use it.

Unfortunately no way to color the line unless the process instance has actually followed the specific line.

Regards,
Ockert
Badge +3
Hmm. How about if I expired the activity before it? Or maybe forced the line rules before it to be true? Just a thought. Hehehe. Thanks again so much!
Badge +11
Sure, have a look at the following forum post: http://forum.k2workflow.com/viewtopic.php?p=2073#2073

Regards,
Ockert
Badge +3
foreach(SourceCode.K2ROM.WorklistItem myWorklistItem in myWorklist)
{
if(myWorklistItem.ProcessInstance.Folio == strFolio)
{
myWorklistItem.GotoActivity("Declined", false);
}
}


this is the code you gave me that will loop through all your worklist items. would you have any idea why it seems to be in an infinite loop everytime i execute it?
Badge +3
i found out what's causing the infinite loop. it is retrieving the current worklist items of the currently logged on user (duh!!). it's because i'm using this whole thing as part of a windows service that triggers the k2 workflow (using K2ROM). therefore i want the workflow items of the destination user to be retrieved. i was doing this for testing purposes of the program. anyway.

Reply