Skip to main content

Hi K2 Guru's,


I need to update the Folio field of a process instance to include the ID of the process instance. For various reasons I don't want to do this in the workflow itself. Currently I take the following steps:


1. Create a process instance using K2ROM API. At this point the ID of the process instance is unknown.
2. Start the process instance (with sync set to false otherwise I run into all sorts of sync problems that goes beyond this discussion).
3. Now I have the process instance ID so using the same ProcessInstance object, I set the folio and then call Update on the process instance object.


I have a few problems (known and unknown) with this. If the process is in a running or active state at this point, the Update call seems to work fine. I'm worried what else could be updated when making the Update call, i.e. the process sets a datafield thats not currently reflected in my process instance and I override it when calling Update? What does Update on the process instance do exactly?


Secondly, if the process instance has completed by the time I call Update, I get an exception... can I check for certain process instance states before calling update? Again, the status I might see on the object is probably not the exact current state of the process?


Am I doing this all wrong, and if so, how can I get the ID of a process instance BEFORE I start it to avoid the issue above?


Thanks,
Gabriel

Hi Gabriel,


The 'update' saves the datafield/folio modified back to the instance.


I am not sure what you mean with 'I'm worried what else could be updated when making the Update call, i.e. the process sets a datafield thats not currently reflected in my process instance and I override it when calling Update?' Can you elaborate?


As far as I know there is no way to check if the process instance is active other than to include the OpenProcessInstance in a try-catch block.


HTH


I assume then that I cannot get a process instance ID before I start the process.


If I call update after the Start call, this could happen.


1. I call start... process starts and maybe update some datafields. I keep holding onto my process instance object in code.
2. I'm still holding onto a local object that represents my process... I now call update on it. The local process instance object might not have the current values of the datafields as they appear in the process, so update overrides the process with the values that was still in my local instance.


I think the best would be to re-think my design on somehow force the team to set the folio field inside the process.


The 'update' saves the datafield/folio modified back to the instance.


When is the datafield modified, i.e. if I set the datafield, then start the process instance and then call Update, is the datafields updated again?


 


Yes if you keep on holding on to the process while allowing others make update to it it could potentially be stale.  You should only get the latest and update it right away when you need it, then close it out.

Reply