Updating Process Instance with K2ROM.dll hangs

  • 30 November 2006
  • 5 replies
  • 0 views

Badge +11
Is this code contained in your custom dll or in a user front end aspx page?
The reason I ask is this...
If it is in your custom dll, you can not connect to a process instance to itself i.e. you can not connect to and update process instance xxxx from within process instance xxxx. The reason for this is that K2.net Server locks the record for this process instance id while it is busy actioning the item. K2.net Server locks this record until the Server Event is completed and then you are trying to access the same process instance through another thread.
I would suggest moving the update code back into K2.net Studio (without the K2ROM stuff) OR making use of a synchronous server event. If you make use of a synchronous server event, you'll have to save the serial number of the event to some place you can pick it up from and action the item. Please refer to the Help file for and explanation of the Synchronous Server Event.

HTH,
Ockert

5 replies

Badge +3
I am not using smartforms but wasn't sure which topic area this fits in.

I have a Server Event, which is the first Event accessed once the workflow commences. Inside the Event I have some code that calls out to my own customized .dlls (these are properly referenced in K2 Studio).

I am able to step through the code by attaching my solution to the K2 Server.


Connection workflowConnection = new Connection();
workflowConnection.Open("localhost");

int processInstanceId = Id_passed_in_as_parameter;

ProcessInstance processInstance = workflowConnection.OpenProcessInstance(processInstanceId);

foreach (DataField dataField in processInstance.DataFields)
{
if (dataField.Name == "externalCheckLoopAmount")
{
dataField.Value = 1;
}
else if (dataField.Name == "externalCheckIdArray")
{
dataField.Value = "this field";
}

}

//***** THE ERROR LINE *****
processInstance.Update();
workflowConnection.Close();


I can step through this code (which is written in C#.NET 2.0) and can see the values of each of the DataFields change as each gets updated.

Once the code hits the processInstance.Update I lose the step over tool and the process is stuck in running mode! I have tried various ways, ie changed the Server Event Item to be a Client Event and made the appropriate changes to run similar code and then tried worklist.update, and also did similar things with the ServerEventItem as well, however nothing seems to work.

Am I doing anything obvious here that is wrong?

The Server Event is running as K2.Synchronous = false however I have tried running that line as true for no luck either. The rest of the code in the event is just a basic call out to my method. Which it does successfully.
I have looked in the database and all the datafields seem correct, although there is never anything in the "_ProcInstDataAudit" table in K2Log, just the "_ProcInstData" table.

is that the issue?

thanks in advance

Steve
Badge +3
That code is in fact in a custom dll, which now all seems to make sense that I can't update the process.

I will try and return the values I need back in to the Server Event to update those DataFields then.

Will this still be locked though if I try to update in the event?

Thanks for the quick reply
Badge +11
Hi Steven,

No, if you use a Synchronous Server Event, K2.net Server will create the event instance and release the locks - waiting for some external system to explicitly finish the event.
If you use an aSynchronous Server Event, K2.net Server will execute the code in the event and continue process execution up to the next "waiting" point - whether that is at a client event or another synchronous server event.

HTH,
Ockert
Badge +3
Thank you Ockert, :D

Now on to the next problem. I have a funny feeling you'll be hearing from me again.

What I have done is exactly as you suggested, I made a call out from a Server Event to a referenced Dll outside of K2, returned a response back to the server event where I then updated the DataFields.
Badge +11
Now on to the next problem. I have a funny feeling you'll be hearing from me again.

:D Don't feel obliged :D

Regards,
Ockert

Reply