Problem Using CreateWorkItem from AgilePart

Applies To

Symptoms

Calling CreateWorkItem with the following parameters inside an AgilePart and it gives an "Object reference not set to an instance of an object" error:

api.CreateWorkItem(w.ActivityInstID, "Process Step", "Administrator",
   new WFTimeDuration(1, WFTimeUnit.DAY, false),
   string.Empty);

Cause

CreateWorkItem API must be called from a manual activity.

Resolution

CreateWorkItem is an API to create a new work item from an existing manual activity. There is a similar API called CreateLinkedWorkitem which is used to create a new work item that links the new item with the existing work item. Both of these API can be used from the manual activities. The activity instance ID in CreatWorkItem must be a manual activity instance ID. api.CreateWorkItem( manualActivityInstanceID, ...)

In other words, they can not be used in AgilePart or Stub and that's why you are getting the error.