Skip to main content

Is there any way to programmatically action a process instance from within a client event based on some defined condition (like if data field = value)


Can I add some code in the “Event Item” on the DataEntry Client Event to automatically action the instance based on some condition?


We have a windows client application communicating with the K2 client and management API. The beginning of our process starts with a DataEntry user. The problem is we need to synchronously start the K2 process to get the available actions for the user. Using the management API I thought we might be able to query the client event actions and show the user. When the user selects an action the K2 process is started asynchronously and a data field is set to the selected action. Code in the Client Event will automatically action appropriately based on the data field value.


If this is not possible is there any way I can remove the client event and just add default lines (add line rule) and utilise the Management API to programmatically determine the possible paths? Normally I could utilise ManagementAPI.GetEventActions(activityEvent.ID) to get the available actions for the client event. How can I get the actions linked to an activity via the management API? I would prefer to automate the client event if possible.


View Process Diagram


View Process Diagram View Code

Hi there,


Are you trying to action this worklist item from within the process, or from your windows client app? If you are doing this from within the process code I would be cautious to use the management API. The KO API should give you much of the functionality you are trying to do, but I have not checked it. If you are doing this from your windows client app then you should use the Sourcode.Workflow.Client API where there is definately functionality to action a work list item automatically. Again, do not use this API from within your process since this can cause thread deadlocks and other nasty things.


HTH,


Hi,


I would like to action the worklist item from within the process in the client event code utilising the KO API. Any ideas where I should put the code that automatically actions a client event and what KO methods I can utilise?


Bib


Hi Bib,


I just did a quick test and unfortunately you can not call actions from within the process code. From your windows app however this would be very easy to do (also as per your second question how to show the list of available actions to the user, you can do that with the Sourcecode.Workflow.Client API).


My main question however is why would you want to automatically action a client event from within the code? If you want to bypass the step based on some external conditions then I would suggest you use a line rule and build that logic in the line rule to bypass the step.


Alternatively if you want to log that the activity has happend for some reason then you can edit the code for the client event in the process. If you look at the C# code behind the WF schedule there are the following lines in each of the methods depending on if the item is send to Internet site, or exchange, etc, the line reads K2.AddWorklist() - so you could wrap that part in an "if" clause to make sure that it only happens if your conditions are met. So in otherwords, instead of calling the action, you prevent that the work list item be assigned in the first place.


Cheers,


Thanks for your help Gerhard!


I have kept my client event but added an additional server event to determine "where to go next" based on some data fields, that way we can automate the process if the initial data field value is what we expect.


Cheers!


Reply