Ask a questionAsk a question
 

QuestionSPWorkflowTask.AlterTask Problem

  • Wednesday, June 24, 2009 4:45 PMwexford Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    I have the following code below in the Approve button in a custom content type that is used by a workflow:

    public

     

    void BtnApprove_Click(object sender, EventArgs e)
    {
    Hashtable taskHash = new Hashtable();
    taskHash[
    "Comments"] = Comments.Text;
    taskHash[
    "Approved"] = "true";
    taskHash["Status"] = "complete";
    SPWorkflowTask.AlterTask(m_task, taskHash, true);
    SPUtility.Redirect(List.DefaultViewUrl, SPRedirectFlags.UseSource, HttpContext.Current);
    }


    The .AlterTask line does not work everytime that it runs through this code.  Sometimes there is a long pause and even though the Task gets updated the workflow then does not move on.  When the .AlterTask does not work then we see an error when trying to re-edit that Task and the error is:

    This task is currently locked by a running workflow and cannot be edited.

    I have seen numerous posts about this problem.

    What is the correct way to update a Task in the workflow that uses a custom content type?

    Is there an internal issue with the .AlterTask method?

    (NOTE: The above code is direct from the HeadCountRequest sample on MSDN)

All Replies

  • Monday, July 06, 2009 10:57 AMwexford Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    anyone?
  • Monday, July 06, 2009 11:08 AMSerge Luca [MVP]MVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    did you try SPContext.Current instead of HttpContext.Current ?


    Serge Luca; blog: http://www.redwood.be
  • Monday, July 06, 2009 11:28 AMwexford Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Yes, I tried the SPContext.Current but the .AlterTask still fails sometimes.  I also tried setting the asynchronus parameter to false but still fails but only sometimes again.

    I also tried m_task.update() instead of .AlterTask but using that the Task is set to "In Progress" and the workflow never resumes.  If I try to edit the Task again it gives the above error about locking.

    There seems to be pattern to why it fails.  It works perfectly sometimes but sometimes is not good enough.

  • Wednesday, July 08, 2009 7:47 AMsangati Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi,

       I am also running in to same situation where I am trying to update the task.

      In my case I am updating the task 1st time it get updated properly and workflow is also get triggered, when I try to

      update the same 2nd time task it will not update the task it is showing the same error and workflow is stuck !

      My Suggestion is that do not update the task twice.  Finally I give up to resolve this issue.


    Thanks,
    sangati
  • Wednesday, July 08, 2009 7:00 PMwexford Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Sangati,

    First try change SPWorkflowTask.AlterTask(m_task, taskHash, true); to SPWorkflowTask.AlterTask(m_task, taskHash, false);

    You will be changing from asynchronus update to synchronus.  This worked somewhat for me but did not completely fix the problem.

  • Tuesday, November 03, 2009 9:04 PM5 luck Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I am having same issue...changed synchronus to false but doesn't work some time..Any solution????
  • Monday, November 16, 2009 10:04 AMwexford Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    5 luck,

    Here is the button click function from my custom approval page maybe it helps:

    public void BtnApprove_Click(object sender, EventArgs e)
            {
                Hashtable taskHash = new Hashtable();
                taskHash["CustomFieldReviewerComments"] = CustomFieldReviewerComments.Text;
                taskHash["CustomFieldRequestApproved"] = "true";
                taskHash["Approved"] = "true";
                taskHash["Status"] = "complete";
                SPWorkflowTask.AlterTask(m_task, taskHash, false);
                SPUtility.Redirect(List.DefaultViewUrl, SPRedirectFlags.UseSource, HttpContext.Current);
            }

    So this first sets the status of the Task to "complete" (note the small 'c').  I then added a Delay Activity (3 minutes) after the OnTaskChanged While Loop.  After the Delay Activity finishes the Task Status gets updated to "Completed" (note capital 'c').

    It never fails for me now but before doing this I was getting random failures where we would have to restart the workflow.  Not acceptable from Microsoft and they still haven't fixed the bug in AlterTask.