Custom ASP.NET SharePoint 2013 task form FAQ

Hi!

In this post I want to collect typical questions, which have high chances to appear if you implement custom SharePoint 2013 ASP.NET task form. I am planning to update this post as soon as I find new information which could be usefull for others. If you have some ideas, what questions and solutions should be included in this post, don’t hesitate to write a comment. Also, if you have a better solution for questions here, please, let me know. It could help us a lot!

Table of contents.

Q1: How to get a reference to a related item from SharePoint 2013 task form?
Q2: Why can’t I update my workflow which was created in Visual Studio?
Q3: Is it possible to use InfoPath task forms in SharePoint 2013 workflows?


Q1: How to get a reference to a related item from SharePoint 2013 task form?

I use the following piece of code to get reference on related item:

string relatedItems = SPContext.Current.Item["Related Items"] + "";
Guid listId;
SPItem relatedItem = GetRelatedItem(SPContext.Current.Web, relatedItems, out listId);
public SPItem GetRelatedItem(SPWeb web, string relatedItems, out Guid listID)
{
    //TODO don't forget to catch possible exceptions
    relatedItems = relatedItems.Trim(new char[] { '[', '{', '}', ']' });
    string[] relatedItemsVals = relatedItems.Split(',');
    Dictionary<string, string> items = new Dictionary<string, string>();
    foreach (var itemsVal in relatedItemsVals)
    {
         string[] keyval = itemsVal.Split(':');
         items[keyval[0].Trim('"')] = keyval[1].Trim('"');
    }

    string itemIDStr = items["ItemId"];
    string listIDStr = items["ListId"];
    listID = new Guid(listIDStr);
    SPList itemList = web.Lists[listID];
    SPItem item = itemList.GetItemById(int.Parse(itemIDStr));
    return item;
}

It seems that there should be a better way to do this, but for the moment it is the only method which I have found and it works well in my cases.

If somebody knows a better way, please, let us know.

This question on MS Forums.


Q2: Why can’t I update my workflow which was created in Visual Studio?

Unfortunately, it seems to be a bug inside SP or WF Manager and in some cases you can’t deploy new version of the WF (it deploys without errors, but you could see only the first deployed version).

This issue on MS Connect.

This question on MS Forums.


Q3: Is it possible to use InfoPath task forms in SharePoint 2013 workflows?

It is impossible. It seems that InfoPath is deprecated in SP2013.

Answer from MSDN:  “Workflow form changed from InfoPath form to ASPX form. Workaround: No workaround is currently available. “

6 thoughts on “Custom ASP.NET SharePoint 2013 task form FAQ

  1. Hi, great series about custom task forms with ASP.NET! I would like to know how to customize the initiation form for a workflow, by using Visual Studio. Do you know how?

    • Hi Borge!

      Thank you very much for your feedback!

      Unfortunately, I haven’t tried to do it yet, but I have seen that when I add “Initiation Form Parameters” to my SPD workflow it creates a default Initiation aspx form, which could be edited using SPD editor.

      As a possible workaround you can create your own Initiation form in VS as it shown on Andrew Connell’s blog and paste it in SPD editor.

      Another probable solution can be to take a look where is the default form located and find the place where workflow and this form connects to each other. When you find how workflow links to this form, most likely, you can change link to your custom initiation form.

      If you find a good solution and have some time, please share it with us.
      I hope I will find some time in the nearest week and will find a way and write an article about it.

      Regards Michael

      • I managed to create a custom initiation form with your help Mikhail. Thank you very much. I’m guessing you will present your/our findings in a blog post soon, so the other readers can benefit from it as well.

        I short:

        1. In the standard WPInitForm.aspx: create a short javascript that catches the HTTP get parameters and sends them forward in a redirect by using window.location = “path/to/custom/init/form?parameter1=firstvalue&parameter2=secondvalue”

        2. Catch the incoming parameters in your custom init form and save them in your class

        3. Start a new workflow by using this code:
        private void StartWF()
        {
        using (SPSite site = new SPSite(_siteCollectionUrl))
        {
        using (SPWeb web = site.OpenWeb())
        {
        Guid subscriptionId = new Guid(_templateId);
        var wsm = new Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager(web);
        var subscription = wsm.GetWorkflowSubscriptionService().GetSubscription(subscriptionId);
        var wfi = wsm.GetWorkflowInstanceService();
        var param = new Dictionary();
        param.Add(“StringVariable”, “Hello from custom init form!”);

        wfi.StartWorkflowOnListItem(subscription, _itemId, param);
        }
        }
        }

  2. Hi, nice post!
    I’m looking for a way to to show the action for approval of a task in Outlook.

    As with the WF of SPD 2010. You can also approve a WF from the email with the special button that appears in the ribbon of Outlook.

    Do you know if it is still possible?

    Thanks,
    Mauro

    • Hi Mauro! Thanks!

      Really, it is an interesting question. Actually, I have not experimented with that, and hope I will find some time to take a look at the question soon.

      Regards, Michael

  3. Hi Borge,
    Thanks for the article. I created custom task forms using your articles successfully. In the workflow initiation form i add parameters to the workflow. I am trying to get worfklow parameters that were passed in the initiation form in the task forms using WorkflowInstance.Properties[“ParameterName”], but could not access them. Is there any other way of doing this? please help

Leave a Reply

Your email address will not be published. Required fields are marked *