Updating Values within a K2 Process Instance
KB000307
PRODUCT
Introduction
The recommended way to update values of a process instance without completing it is to use the Actions["UpdateWorkItem"].Execute() method. The Action must be configured to support the updating of the work item in order to use the Execute method in the API.
Configure the Action in K2 Designer for Visual Studio
The Add Action dialogue screen contains a radio button option that enables the Action to be updated without the Worklist item being completed:
This radio button must be selected in order to programatically update the value within a process instance.
Update the Work Item Using the K2 API
The recommended method uses an "update" action, as opposed to firing the ProcessInstance.Update() method, so will work without Admin permissions:
wi.ProcessInstance.DataFields["TestDF"].Value = "2";
wi.Actions["UpdateWorkItem"].Execute();
Remember that the Action must be configured using the This action will update the work item option during the design of the process, as demonstrated in the K2 Designer for Visual Studio section above.
The following sample will now only work if it is called by a user with Admin permissions on the process:
wi.ProcessInstance.DataFields["TestDF"].Value = "2";
wi.ProcessInstance.Update();