You are not authorized to respond to this item

549 views Asked by At

I am programmatically trying to delegate the sharepoint 2013 workflow task to "DOMAIN\Test2" user from "DOMAIN\Test1" user. Its delegating to "DOMAIN\Test2" user but when I try to access the task item url using the delegated user("DOMAIN\Test2") account, I am getting the below error:

"You are not authorized to respond to this item."

using (SPSite currentSite = new SPSite("http://tst:001/sites/Test"))
    {
        using (SPWeb currentWeb = currentSite.OpenWeb())
        {

            string tasksList = "Workflow Tasks";                    
            SPUser delegateTouser = currentWeb.EnsureUser("DOMAIN\\Test2");
            SPListItem listItem = currentWeb.Lists.TryGetList(tasksList).GetItemById(101);
            listItem[SPBuiltInFieldId.AssignedTo] = delegateTouser;
            listItem[SPBuiltInFieldId.WorkflowVersion] = "1";
            listItem.Update();
        }
    }
1

There are 1 answers

1
Habib Adıbelli On

Use RunWithElevatedPrivileges when you open a site:

SPSecurity.RunWithElevatedPrivileges(delegate(){
using (SPSite currentSite = new SPSite("http://tst:001/sites/Test"))
{
    using (SPWeb currentWeb = currentSite.OpenWeb())
    {

        string tasksList = "Workflow Tasks";                    
        SPUser delegateTouser = currentWeb.EnsureUser("DOMAIN\\Test2");
        SPListItem listItem = currentWeb.Lists.TryGetList(tasksList).GetItemById(101);
        listItem[SPBuiltInFieldId.AssignedTo] = delegateTouser;
        listItem[SPBuiltInFieldId.WorkflowVersion] = "1";
        listItem.Update();
    }
}
});