views:

20

answers:

1

Hi,

I'm trying to call AlterTask on a newly created Sharepoint task to add extended properties to my task, and a NotSupportedException is thrown.

What's going on?

+1  A: 

The newly created task is actually a SharePoint ListItem. ExtendedProperties is specifically a Workflow Task property.

As per the MSDN documentation:

The content type of the item passed to the task parameter is not derived from the WorkflowTask content type.

This means that Content Type of the SPListItem that represents your new Task must be set to "Workflow Task" before the AlterTask method can be called on it:

    Dim selectedTaskList As SPList = web.Lists(taskListName)

    ' Create a new task item
    Dim newTask As SPListItem = selectedTaskList.Items.Add()

   ' Turn the new task item into a Workflow Task
    Dim newTaskContentType As Microsoft.SharePoint.SPContentType = web.AvailableContentTypes("Workflow Task")
    newTask("ContentTypeId") = newTaskContentType.Id

   ' Now the AlterTask method will work.  (assume you've alreade declared a hashtable of properties to set)
    Microsoft.SharePoint.Workflow.SPWorkflowTask.AlterTask(newTask, myHashTable, True)
Michael Rodrigues