Thursday, February 24, 2011

Updating DataField Values within a K2 Process Instance without Admin Access

We had an issue while updating the datafield values without executing the action in the application form. If we use ProcessInstance Update method, it was obvious that we need to provide the admin rights for all the users which is not an ideal solution. So we found in the K2 Blackpearl Arcticles that we can update the Data Fields with an Action seperately created for that with in the workflow defintion. The information is described below.

 

Updating Values within a K2 Process Instance

KB Number:KB000307

Introduction

When updating values (i.e. a data field) of a process instance without completing the process in pre-0807 releases of K2 blackpearl it was possible to use the [WorkListItem].[ProcessInstance].Update() method. In K2 blackpearl 0807 the [WorkListItem].[ProcessInstance].Update() method now requires a user with process Admin rights.

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: Click here  to see the screen shot that shows the configuration for Save with action name UpdateWorkItem.
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:

SourceCode.Workflow.Client.WorklistItem wi;
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:

SourceCode.Workflow.Client.WorklistItem wi;
wi.ProcessInstance.DataFields["TestDF"].Value = "2";
wi.ProcessInstance.Update();

 

 

 

Access to XMLHttpRequest at 'from origin has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https. .net core angular

Issue: The angular application was getting error from API that the origin has been blocked by CORS policy. Solution: Make sure that the...