How to update the action on a v1 task?

Mar 3, 2010 at 9:22 PM

 I am trying to update the action on a v1 task definition but cannot work out how to do it.

You cannot do:
ExistingTask.Definition.Actions.Clear();
because you get the message:
There can be only a single action and it cannot be removed.

You cannot do:
ExistingTask.Definition.Actions[0] = new ExecAction(...
because the left side is read only.

You cannot change the parts of the action by:
ExistingTask.Definition.Actions[0].SomePropertyToChange

So how do I replace/change the action on an existing task?

Coordinator
Mar 4, 2010 at 6:35 AM

Let me start by apologizing. The way this works currently is just bad design and I'll look at a way to resolve it in the next release. To make it work for now you can use a method like this one:

void UpdateFirstAction(Task t, Action action)
{
   if (t.TaskService.HighestSupportedVersion >= new Version(1, 2))
      t.Definition.Actions.RemoveAt(0);
   t.Definition.Actions.Add(action);
}

 

ActionCollection.Add will actually replace the current action under V1. Under V2, it will add a second action so you really should put a version conditional in before the call like I have done in the method.

I'll post a message to this discussion when I have implemented a more intuitive design.

Coordinator
Mar 4, 2010 at 6:37 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Mar 4, 2010 at 9:01 PM

Thanks for that I've got it working now.