Workflow Tasks and Permissions: Why doesn't this work?



    Hi all,


    I have a workflow that reads a custom list, takes a few items, creates tasks for those items, waits until all those tasks are completed, then repeats for a different batch of items from the custom list. The problem I'm running into is when a user reassigns the task to someone else, the new assignee does not have permissions to edit the item, due to the setting of SpecialPermissions on the CreateTask (which is necessary to allow the original person to have permissions on the task in the first place). So then I create the task (CreateTaskActivity) and then have a while loop that has a OnTaskChangedActivity inside. When the task is marked as completed, the loop ends, and life moves on. But when I try this code block (bound to the Invoked property of the OnTaskChanged), I get an error that really is just blowing me away.


    Here's the code block:

    private void afterTaskChanged(object sender, ExternalDataEventArgs e)


    SPRoleDefinition RoleDefinition;

    SPUser user;

    SPRoleAssignment RoleAssignment;



    ((ReplicatorChild)((Activity)sender).Parent.Parent.Parent).EventCompleted = afterProperties.ExtendedProperties.ContainsValue("Completed") || (afterProperties.PercentComplete == 1F);


    RoleDefinition = workflowProperties.Web.RoleDefinitions.GetByType(SPRoleType.Administrator);

    user = workflowProperties.Web.SiteUsers[afterProperties.AssignedTo];

    RoleAssignment = new SPRoleAssignment(user.LoginName, user.Email, user.Name, user.Notes);






    catch (Exception ex)


    throw new Exception("**" + afterProperties.TaskItemId.ToString() + "** " + ex.StackTrace);


    afterProperties = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();




    The error that shows up on my history list is: **62**    at SequentialTaskDistributor.TaskDistributor.afterTaskChanged(Object sender, ExternalDataEventArgs e)


    But I know after playing around with things that it is caused by the GetItemById function.

    I look at my TaskList and sure enough, there is a task with the ID number specified.

    But the error is telling me that the Given Value does not fall inside the specified range or something along those lines.


    Any help? Might there be a better way to set the permissions?




    Tuesday, September 18, 2007 7:12 PM