Skip to main content
When I try execute this in any event or "Default Server Event", the compile returns error that Item is ReadOnly.

I want to modify some of the field values on the server side for specific activities.

k2.ProcessInstance.DataFields.item("PRIMARY_USER") = "xyz"
The proper syntax should be:


k2.ProcessInstance.DataFields.item("PRIMARY_USER").Value = "xyz"
Thanks, how do I set the activity data field within Destination Queue code?

I can't locate

K2.ProcessInstance.ActivityInstances.DataFields

--------------

I had to create a Server Event, and set the ActivityDataField to a ProcessDataField, then in Destionation Queue code use that ProcessDataField.... is that the way it's meant to be used?!
Do you mean within Destination Rule code for an Activity? There is not really any Destination Queue code.

Assuming you mean Destination Rule, you do not have access to Activity Data Fields. Activity data actually exists at the ActivityInstanceDestination level (remember an activity can have multiple destinations, or assigned users, each will get his/her own complete and independent copy/instance of the activity events and data). As such, the purpose for the destination rule is to determine how will be assigned this activity and thus how many instances of the activity will be created. As such, the actual copies of the Activity data does not exist yet within the destination rule because the actual destinations do not get created until after this rule processes.

If you need to do something with activity data, you can put a server event in the activity and reference in the code as follows:

K2.ActivityInstanceDestination.DataFields["MyActivityDataField"].Value = "abc";

Please note, could potentially fire all destination instances (users) depending on its location in the activity and number of slots, which may or may not be what you are looking for.
I found this in Help, we have to define a generic Object in order to access it, that's why it wasn't easy to find.

Dim ActInstDest As Object

For Each ActInstDest In K2.ActivityInstance.Destinations
If ActInstDest.DataFields("RECALLABLE").Value = "Y" Then
K2.Destinations.Add(DestinationType.User, k2.StringTable("WorkflowAdmin"))
End If
Next

I tested this code in Destination Rule, it doesn't work I am assuming the # of destinations is 0 at that point.

You'll have to set up a server event after Client Event and use something like:

Sub Main(Byval K2 as ServerEventContext)
K2.Synchronous = True

k2.ActivityInstanceDestination.DataFields("ACTIONTAKEN").Value = K2.ProcessInstance.DataFields("ACTION").Value
End Sub
I'd like to alter the default Activity Data value in a Server event prior to the Client Event in an activity. Is it possible to do that?

The reason is that based on another value, I need to change the default Activity Data Value.
Should not be a problem. The only thing you need to be aware of is the fact that the Server Event will execute for each and every Destination User - if you write to a db (for example) in this server event, the value will be overwritten x times (once for each destination) but in your case, changing default activity datafield values, should be no problem.

Regards,
Ockert
Thanks, what's the syntax to do it in the server event (prior to client event), since a lot of the methods are referring to ActDestInstance but destination does not exist till client event is called.
It will look exactly the same as the server event you had after the client event:

Sub Main(Byval K2 as ServerEventContext)
K2.Synchronous = True

K2.ActivityInstanceDestination.DataFields("ACTIONTAKEN").Value = K2.ProcessInstance.DataFields("ACTION").Value
End Sub

As soon as the first event fires - irrespective of whether it's a server event or client event, the destinations will exist. Actually, the ActivityInstanceDestination objects will exist just after the Destination rule of the Activity has executed.

HTH,
Ockert

Reply