none
How to alter SP2013 workflow task from ASP task form? RRS feed

  • Question

  • Hello

    I have created SPD workflow with a custom ASP form. My form opens when clicking on a task link and I can show information about the task. Now I want to alter the task after pressing a button, but can't make it work.

    Code of my click handler:

    Hashtable hashTable = new Hashtable();
    hashTable["PercentComplete"] = 1;
    SPWorkflowTask.AlterTask(this._taskListItem, hashTable, true);

    but it seems like this approach doesn't work, I am getting the following error:

    NotSupportedException. Specified method is not supported. at Microsoft.SharePoint.Workflow.SPWorkflowTask.SetWorkflowData(SPListItem task, Hashtable newValues, Boolean ignoreReadOnly) at Microsoft.SharePoint.Workflow.SPWorkflowTask.AlterTask(SPListItem task, Hashtable htData, Boolean fSynchronous) at NewServerForms.Layouts.NewServerForms.ApprovalTaskForm_Edit.btnSubmit_Click(Object sender, EventArgs e)

    _this.taskListItem is not null (I have checked it) and was initiated as follows in the Page_Load:

    this._listGuid = Request.Params["List"];
    this._listItemId = Request.Params["ID"];
    using (SPWeb web = SPContext.Current.Site.OpenWeb())
    {
       this._taskList = web.Lists[new Guid(this._listGuid)];
       this._taskListItem =  this._taskList.GetItemById(Convert.ToInt32(this._listItemId));
    }

    I have two ideas, why it is hapenning:

    1. Probably I have to use another approach for SP2013 WFs.

    2. As I can see in msdn, this error could be if my content type is not derived from WorkflowTask Content Type.

    Most likely it is really the latter, because my task content type looks as follow:

    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <ContentType ID="0x0108003365C4474CAE8C42BCE396314E88E51F00F35251B8B0C24C4986783D649A695D00" Name="TaskApproveNewServer" Group="MyGroup" Description="MyCT" Version="0" Overwrite="TRUE">
        <FieldRefs>
          <FieldRef ID="{6f78c128-5660-4835-9b03-4c08d5eef709}" DisplayName="AbsenceStatement_Status" Required="false" Description="" Hidden="false" Name="AbsenceStatement_Status" Sealed="false" />
          <FieldRef ID="{55B29417-1042-47F0-9DFF-CE8156667F96}" DisplayName="$Resources:_FeatureId57311b7a-9afd-4ff0-866e-9393ad6647b1,TaskOutcomeField_DisplayName;" Name="TaskOutcome" Sealed="FALSE" />
        </FieldRefs>
        <XmlDocuments>
          <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
            <FormsUrl xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
              <Display>_layouts/15/NewServerForms/ApprovalTaskForm_Edit.aspx</Display>
              <Edit>_layouts/15/NewServerForms/ApprovalTaskForm_Edit.aspx</Edit>
            </FormsUrl>
          </XmlDocument>
        </XmlDocuments>
      </ContentType>
    </Elements>

    Its ID derived from WorkflowTask, but there is no Inherits="TRUE" attribute (it was removed, because I can't use custom forms when it is true because of the well-known issue).

    So, could you suggest me, how can I alter the task using my custom ASP form?

    Every suggestions are very appreciated.

    UPDATE1:

    It seems like the cause of the issue the former. At least, now I added Inherits="TRUE" attribute (and set forms from the Feature receiver), but anyway I am getting the same error.

    Kind regards, Michael (http://sp2013-blog.com)







    • Edited by MikhailSP Tuesday, March 12, 2013 7:18 PM
    Wednesday, December 26, 2012 10:09 AM

Answers

  • Hi,

    It seems like the SPWorkflowTask.AlterTask method really doesn't work for 2013 workflows, but we can change task fields directly and it works well.

    For instance, instead of 

    Hashtable hashTable = new Hashtable();
    hashTable["PercentComplete"] = 1;
    SPWorkflowTask.AlterTask(this._taskListItem, hashTable, true);



    We could write

    this._taskListItem["PercentComplete"] = 1;
    this._taskListItem.Update();

    Don't forget to add Update.

    Hope it helps somebody. If so,please press the upvote button :-).

    UPDATE1: I have just written a walkthrough: how to implement custom task forms for SP2013 WFs.



    • Marked as answer by MikhailSP Thursday, January 3, 2013 5:27 PM
    • Edited by MikhailSP Tuesday, March 12, 2013 7:28 PM
    Thursday, January 3, 2013 5:27 PM

All replies

  • Hi,

    It seems like the SPWorkflowTask.AlterTask method really doesn't work for 2013 workflows, but we can change task fields directly and it works well.

    For instance, instead of 

    Hashtable hashTable = new Hashtable();
    hashTable["PercentComplete"] = 1;
    SPWorkflowTask.AlterTask(this._taskListItem, hashTable, true);



    We could write

    this._taskListItem["PercentComplete"] = 1;
    this._taskListItem.Update();

    Don't forget to add Update.

    Hope it helps somebody. If so,please press the upvote button :-).

    UPDATE1: I have just written a walkthrough: how to implement custom task forms for SP2013 WFs.



    • Marked as answer by MikhailSP Thursday, January 3, 2013 5:27 PM
    • Edited by MikhailSP Tuesday, March 12, 2013 7:28 PM
    Thursday, January 3, 2013 5:27 PM
  • Were you able to find a way to Approve and Reject the task in 2013 workflows?
    Friday, April 26, 2013 11:11 PM
  • Hi Ryan,

    Yes, you can use the following piece of code for that:

    private void CompleteCurrentTask(string outcome)
            {
                //Completing a task            
                SPListItem item=SPContext.Current.Item;
                item["TaskOutcome"] = outcome;
                item["PercentComplete"] = "1";
                item["Status"] = "Completed";
                item.Update();
    
                //Closing the form
                SPUtility.Redirect(string.Empty, SPRedirectFlags.UseSource, Context);
            }

    Probably in addition to that you will be interested in creating custom ASP.NET task form. I have written a walkthrough about that on my blog: Creating SPD 2013 Workflows. Part 2/3: implementing custom ASP.Net task form

    _______________________________

    Regards, Michael

    Saturday, April 27, 2013 4:52 AM