tobey74
Scholar

How to get/check status of an activity instance from c#?

Hi

 

I want to bulk change running workflow instances and jump to a specific activity by using the Workflow Management APIs GotoActivity method. But before just ending the workflow instance, I want to make sure that the currently loaded instance is at the expected Activity and that activity is in Status=Active.

 

How/where do I get the currently active activity for the workflow instance and see its status is Active?

When I examine the Activity class there is no Status property.

 

I use something like this:

 

WorkflowManagementServer wfmServer = new WorkflowManagementServer();
wfmServer.CreateConnection();
wfmServer.Connection.Open(ConfigurationManager.ConnectionStrings["k2db"].ToString());

 

 

Activities acts = wfmServer.GetProcInstActivities(12345);


wfmServer.GotoActivity(procInstance, "Finish");

 

 

Best regards, Peter

0 Kudos
Reply
2 Replies
tobey74
Scholar

Re: How to get/check status of an activity instance from c#?

I have solved my problem for now by verifying Activity Instance Status through the SmartObject Client framework. 

 

I used K2 SmartObject Tester to create C# class for the Activity Intance SMO.

 

After that I can do something like this:

 

Activity_Instance ai = new Activity_Instance(ConfigurationManager.ConnectionStrings["k2db"].ToString());
ai.ProcessInstanceID = procInstance;
ai.Status = "Active";
ai.ActivityName = "Activity name of where I expect this process instance to be situated at";
DataTable dt = ai.List();

 

if (dt.Rows.Count == 1)

  wfmServer.GotoActivity(procInstance, "Finish")

 

 

/peter

 

0 Kudos
Reply
Olivier1
Apprentice

Re: How to get/check status of an activity instance from c#?

Hi  @tobey74 ,

 

Yes, you can use the GoToActivity with API and the advantage is that you can specify the FromActivity in order to not stop all other activities but only one.
This API is already used by the very intersting custom service broker Workflow Management:
https://community.k2.com/t5/K2-blackpearl/WorkflowManagement-Service/ba-p/65416
 

Warning:  we have encountered a problem with GoToActivity (K2 Five 5.1 to 5.4 at least)
Following the use of the go to activity inside a Split/Merge the workflow stops at the “Merge” step next. Issue appears with Go To Activity from Management site with K2 Five new designer (Split and merge was not possible in K2 Studio).
The issue appears too with Process Version Migration Utility: https://community.k2.com/t5/K2-blackpearl/Process-Version-Migration-Utility-v3-0-6/ba-p/98975
 
At the same time, I asked to an impacted customer to create 2 K2 Ideas created in order to maximize the chances of having actions taken on this subject which can be blocking.
 
I therefore invite you to vote on these K2 ideas:
https://ideas.k2.com/ideas/APIT-I-1554
Fix issue: after go to activity, the workflow stop at the next merge step.
 
https://ideas.k2.com/ideas/APIT-I-1555
Add warning message in case of use of Go to activity from Management site to avoid important issue with split branches.
 
 
Please vote on them and don't hesitate to transfer to your colleagues who have a K2 account: For a K2 Idea to possibly be considered, you need at least 20 votes.
 

In addition, a normal behavior to know is the following:
If there are several activities in progress on the same instance of worklfow and that one uses the GoToActivity on any activity,
all the activities are finished and it does not will remain more than that specified by the Go To Activity.
However, it is possible to do a Go To Activity for a specific activity via the API.
This functionality has been implemented in the Workflow Management: https://community.k2.com/t5/K2-blackpearl/WorkflowManagement-Service/ba-p/65416
With this tool, we have possiblity to specifiy the "FromActivityName".
SmartObject service tester++ URL (https://community.k2.com/t5/General-K2-Utilities/SmartObject-Service-Tester-plus-plus/ba-p/92426😞
SmartObject ExplorerDefaultSmoTask_managementMethodsGotoActivity -E ProcInstID=123;FromActivityName=Task1;ActivityName=Task3
 
 
Best regards,
Olivier
0 Kudos
Reply