Skip to main content

Dear all,

 

Our workflow have such scenarios that we get destinations using Smartobject interface, sometimes this interface get no destination, if such things happens, this activity will marked as "approved" and step to the next action.

 

I have tried to use Default Server Event with such code:

 

 

public void Main(Project_ae1cc532a7e440c8bde40460075f2375.EventItemContext_a0c29afc7f70413d9cd25cfd60bf4816 K2)
{
string defaultActivityParticipants = K2.ProcessInstance.DataFieldse"_DEFAULT_ACTIVITY_PARTICIPANTS"].Value.ToString();

if (K2.ActivityInstanceDestination.Destinations.Count == 0
|| (K2.ActivityInstanceDestination.Destinationsi0].Type == DestinationType.User
&& K2.ActivityInstanceDestination.Destinationsi0].Name == defaultActivityParticipants))
{

K2.ActivityInstanceDestination.ActivityInstance.DataFieldse"Outcome"].Value = "Approve";

K2.ExpireActivity(K2.ActivityInstanceDestination.Activity.Name);
}
}

 

These code should be work but when we test it, the status of this activity is "Empty" and the process get into "Error" status, the log we got is "An Activity with a client event should at least have one destination".

 

Can anyone help us to implement if there is no destination, the this activity should be skip as "Approved".

 

Many thanks

The approach you outline won't work, because as you noted, K2 requires at least one destination for an activity. There are a few ways you could approach this.

 

1) You could look up your destination users in a step prior to the activity in question and based on that effort route the process around the activity that isn't needed and update any data tables according to your requirement. This is probably the most "K2" way of doing things as it avoids any custom code. Not that you should avoid custom code, but keeps things purely out of the box.

 

2) You could use destination sets, have one set that is used if your destination has a user and if not, use another destination set that uses that K2 service account as the destination. If your logic, you could then potentially check to see if the K2 service account is the only destination and if so do what you want to do. Doing the quick math in my head this means that you could end up with 3 different calls to your data source to retrieve the destination user, twice to decide if there is or is not a user and one additional time to use the user as the destination if present. I would still recommend looking up your destination user in a step prior, storing in a data field and then using that data field in logic in either destination sets and/or in your code logic.

 

The caveat to this is I don't know how you are retrieving destination users, so assuming that is pretty straight forward and via smart objects then one of these may meet your requirement.

 

S.


Reply