Skip to main content
I'm trying to save the Serial number inside the Default CLient generated code - but somehow the serial number that i save, is not the correct one, the eventid is always off by a couple of number ?
Could someone explain why ? and how ?
Thx.

public void Main(ClientEventContext K2)
{
try
{
HTTPFunction(K2);
}
catch (System.Exception ex)
{
throw new System.Exception(ex.Message);
}
}
public void HTTPFunction(ClientEventContext K2)
{
Forecast_Object.Mission_Main oAssembly = new Forecast_Object.Mission_Main();
oAssembly.scon = scon;

string strURL = "";
strURL = "http://wsmrc2wsdmvm001:8095/ForecastCalendar/SchedulerApproval.aspx?sn={SERIALNO}";
string sSerialNumber = K2.SerialNumber;
strURL = strURL.Replace("{SERIALNO}",sSerialNumber);

oAssembly.K2Serial_Number = sSerialNumber;
oAssembly.update();

K2.AddWorklist("ASP",System.Web.HttpUtility.UrlPathEncode(strURL));
It's most probably because you've got more than one Destination User specified for the Activity. Remember, a new serial number will be generated for EACH destination user and you probably only store the last serial number generated - overwriting all the previous ones.

Hope this makes sense,
Ockert
You're absolutely right ....Thx
Given that a new serial number will be generated for each destination, is it not possible to use the serial number as a confirmation number once a process has been submitted for the submitter to track the process status?
The SerialNumber is a combination of [K2Server,ProcessInstanceID,EventInstanceID] making each SerialNumber unique on the K2.net 2003 Server.

I assume if you have multiple client events in an activity the serial # will change also when it gets to the 2nd client event.

I am going to assume that ProcessInstanceID is unique across the K2 system (not just for a specific process).
That's correct so does that mean I can't use that as a confirmation or reference number when the submitter submits the process.

How would they be able to track the process instance? Does the workspace list the process and where the workflow has gone if they have view rights?
A serial number is unique for each Event and each Destination.

If the user has 'View' or 'View Participate' rights, he/she will be able to view the Viewflow diagram for that specific process instance. The Viewflow component only needs the ProcessInstanceID as input parameter.

ProcessInstanceID will remain the same for the duration/lifetime of the process instance.

HTH,
Ockert
You may also consider utilizing the Folio field, which is a descriptive label for a process instance. It can be assigned anything you want it to be and it will display in K2 Workspace, so a user can easily get some meaningful visual descriptiption of the process instance.

The folio can be set within a Server Event in the K2 Studio as follows:

K2.ProcessInstance.Folio = "Invoice # 22222";

The actual value of the Folio field can be pretty much anything you want; it's usually a single process datafield or a combination of a few to providding a meaningful reference for that process instance for the purposes of reporting.
I tried to create my own confirmation number and created a process data field to stick it in. The problem I'm having is the process ID does not seem to get created until the StartProcessInstance occurs. Then, I tried to save the ID as part of my confirmation in the data field and used the Update method, but it says I do not have the right to open the process. I take it as the submitter, I can't update the process? Is it possible to update the process again once I call the StartProcessInstance?

Here's my code:

oK2Connection.StartProcessInstance(oNewProcessInstance, true);

//Save to Confirmation Number
oNewProcessInstance.DataFields["ConfirmationNo"].Value = oNewProcessInstance.ID.ToString();
oNewProcessInstance.Update();
That is correct, the ID of the new process instance is not created until the process is actually started.

It is also correct that the submitter/originator does not automatically have the rights to update the process data fields once he/she has submitted.

Can you please explain what it is that you are trying to do with the Process Instance ID?

If it is simply to populate a Process data field with it, which don't you just do it within a Server Event that resides within an Activity that is fired immediately after Start and remove this logic from the calling application all together?
Hi Bob - I'm trying to save the confirmation field onto the process. Since the ID is created after the Startprocess is called I need to be able to assign it to a process datafield (if the submitter wants to do a search on the confirmation number for historic reasons).

I tried your suggestion of saving the confirmation field in a server event but could not get it to compile. The compiler was complaining about the field being readonly and An object reference is required for the nonstatic field, method, or property 'System.Web.HttpResponse.Redirect(string)'

Any idea what I'm doing wrong?


.ToString());
}

Vinny,

There are a couple of issues with the above Server Event code.

1. The Process Data Field should use the .Value property to store the actual data.
2. The line of code that attempts to redirect is out of context for K2. A System.Web.HttpResponse.Redirect() is appropriate only within an ASP.NET page. K2, being a server side application, has now ability to physically manipulate the ASP.NET session. This line of code should be moved back to the ASP.NET page, following:


oK2Connection.StartProcessInstance(oNewProcessInstance, true);


Below is an example of how I think the Server Event should look:

.Value = K2.ProcessInstance.ID.ToString(); 
}

Reply