0

I am using SpecialPermission in my Sequential Workflow createTask_MethodInvoking() function

HybridDictionary taskPermissions = new HybridDictionary(); taskPermissions.Add(SPTaskProperties.AssignedTo, SPRoleType.Contributor); createTask1.SpecialPermissions = taskPermissions;

which is working fine ..BUT when I edit the task and change the "Assigned TO" field to some other user then that task is not showing in that user task list(workflow task).

I am using following piece of code ,which is not working.

HybridDictionary taskPermissions = new HybridDictionary();
Hashtable ht = new System.Collections.Hashtable();
ht[SPBuiltInFieldId.WorkflowVersion] = 1;
ht[SPBuiltInFieldId.AssignedTo] = SPTaskAfterProperties.AssignedTo;
taskPermissions.Add(SPTaskAfterProperties.AssignedTo, SPRoleType.Administrator);
createTask1.SpecialPermissions = taskPermissions;
createTask1.SpecialPermissions = taskPermissions; 
SPWorkflowTask.AlterTask(task, ht, true);

suggest the way to reassign the task to other user with specialPermission.

1 Answer 1

0

This is an issue I have fought with time and time again. The SpecialPermissions property of the CreateTask activity does not seem to update permissions on an already existing task.

In theory, you should be able to set up your OnTaskChanged event to detect a reassignment and permission the task item based on that. I've had iffy results doing it this way as well.

The solution I have settled on for all of my workflows has been to implement an ItemUpdated event receiver on the Tasks list that the workflow uses. In this event receiver, whenever the item is updated, you can check if the 'Assigned To' has changed, and re-permission appropriately.

Edit: Here's a snip of code that I use. In my case reassignments can be to a group or a specific user, so I handle both situations.

// Compare the new string value of the 'Assigned To' field on the task to the old value
// in the event afterproperties. If they differ, this task has been reassigned.
if (!GenericUtilities.StringValueFromField(listItem["Assigned To"]).Equals(properties.AfterProperties["AssignedTo"]))
{
    // Break role inheritance if not already done
    if (!listItem.HasUniqueRoleAssignments)
    {
        // Reset inheritance first, to wipe out any other permissions
        listItem.ResetRoleInheritance();
        listItem.BreakRoleInheritance(false);
    }

    // Determine if the assigned user is a group or user, and assign permissions as necessary
    SPFieldUserValue field = new SPFieldUserValue(listItem.Web, GenericUtilities.StringValueFromField(listItem["Assigned To"]));
    if (field.User != null)
    {
        SetItemLevelPermissions(listItem.Web, listItem, field.User);
    }
    else
    {
        SPGroup assignedGroup = listItem.Web.SiteGroups[field.LookupValue];
        SetItemLevelPermissions(listItem.Web, listItem, assignedGroup);
    }
}

The SetItemLevelPermissions method just takes the SPPrincipal that I pass and grants permissions on the task:

SPRoleDefinition roleDefinition = setSPWeb.RoleDefinitions["Contribute"];
SPRoleAssignment roleAssignment = new SPRoleAssignment(principal);
roleAssignment.RoleDefinitionBindings.Add(roleDefinition);
setListItem.RoleAssignments.Add(roleAssignment);
3
  • thanks for reply ... I think we both had the same problem so can you plz provide a piece of code that reassign task with permission. Because you have mentioned event receiver that solved your problem.
    – Atulya
    Nov 27, 2013 at 4:49
  • I think we both had the same problem so can you plz provide a piece of code that reassign task with permission. Because you have mentioned event receiver that solved your problem.
    – Atulya
    Nov 27, 2013 at 18:06
  • Sorry for the delay, I updated the answer with some code.
    – Sean
    Dec 4, 2013 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.