How to update ActivityInstanceDestination.DataFields programatically?

  • 26 September 2007
  • 8 replies
  • 9 views

Badge +4

Hi,



I need to update some ActivityInstanceDestination.DataFields programatically. My code looks like this:




Connection.Open(connectionString);
WorklistItem worklistItem = Connection.OpenWorklistItem(serialNumber, "ASP", true, true);
UpdateProcessDataFields(worklistItem.ProcessInstance); // Get data from UI and puts into process' datafields
UpdateActivityDataFields(worklistItem.ActivityInstanceDestination); // Get data from UI and puts into activity's datafields
worklistItem.ProcessInstance.Update();
worklistItem.Release();
Connection.Close();

My problem is that the Activity's datafields doesn't seem to update, only the Process' datafields...

Any tips?

Sincerely,

Cato Antonsen

 


8 replies

Badge +4

Sure - very simplified:

private void UpdateProcessDataFields(ProcessInstance process)

{

    process.DataFields["FirstName"].Value = tbFirstName.Text;

    process.DataFields["LastName"].Value = tbLastName.Text; 

}

 

private void UpdateActivityDataFields(ActivityInstanceDestination destination)

{

    destination.DataFields["Test1"].Value = tbTest1.Text;

    destination.DataFields["Test2"].Value = chkTest2.Checked; 

Badge +4
Btw, when debugging I do see jcorrect values in both the process instance's datafields and activity instance's datafields just before the I do the update/release ...
Badge +4

Hi,



The same thing happen if I set the activity's datafields in same code context as I open the process instance:



Connection.Open(connectionString);
WorklistItem worklistItem = Connection.OpenWorklistItem(serialNumber, "ASP", true, true);
worklistItem.ProcessInstance.DataFields["Task"].Value = "Test"; // This gets saved
worklistItem.ActivityInstanceDestination.DataFields["Check_Subtask"].Value = true; // This don't get saved
worklistItem.ProcessInstance.Update();
worklistItem.Release();
Connection.Close();


Please note that I can see that the datafields do get updated when I debug, but it seems that K2 don't save them when I do the update and release the worklist item.



Can someone (from K2?) confirm that what I'm trying to do should be possible and is working for them?



Sincerely,
Cato Antonsen
 

Badge +4
I might add that what I'm trying to do is storing the state of several checkboxes on a client page. Only when all checkboxes are checked, the event is finnished and should continue to next action...
Badge +2

Hi Cato,


Which version of K2 [blackpearl] are you using? I remember this being a bug in one of the Beta versions. Please note that you can request an evaluation of K2 [blackpearl] RTM from K2.com if required. Also please ensure that you've installed K2 [blackpearl] Hotfix 1 if you are using RTM. Hope this helps.


Cheers,


Seb

Badge +4
Has got a confirmation that this is a known issue - even in hotfix 1.
Badge +1

Was this issue resolved ?  I'm experiencing the same problem.

Badge +10

Hi,


The Update() method on the ProcessInstance object is only for administrative updates and requires the user executing it to have Admin rights on the process. This is not the recommended approach to save data fields from the client pages.


The better approach would be to use K2 Actions to save the data field values. If you want to save the data fields without moving the process on to the next activity, execute an Update action. If you want to save the data field values and complete the item so that the K2 process can continue, execute a Finish Action. This will save the data correctly.


Hope this helps!

Reply