Skip to content

InfoPath Form Services and Workflow Tasks

InfoPath Forms Services and Workflows in SharePoint can deal a one-two punch to your business problems.  It’s a simple form to create and a framework to take action on those forms.  However, there are a few caveats, however, one of them is that getting a form to open up in InfoPath Forms Services can be setup in the library where the form is stored but when a workflow task is created the link back to the item will try to open up in the InfoPath client (if present) – not in forms services.

Getting the document library to force the InfoPath form to open in InfoPath Forms Services can be done from the document library home page by selecting  Settings-Document Library Settings-Advanced Settings and changing the Browser-enabled Documents to Open browser-enabled documents to “Display as a web page”.

If you want to change the link so that it will open in the browser you’ll have to add a handler to the CreateTask activity.  I’ve added some support routines to break the code up into meaningful chunks. (that you can copy into your project).  The result looks something like:

Help Your SharePoint User

private void createTask_MethodInvoking(object sender, EventArgs e)
{
string formsServerUrl = GetFormsServerUrl(workflowProperties.Item);
WorkflowTaskProperties.ExtendedProperties[SPBuiltInFieldId.WorkflowLink] = CreateUrlFieldString(“Open form for – ” + workflowProperties.Item.File.Name, formsServerUrl);
}

public static string CreateUrlFieldString(string name, string url)
{
return (string.Format(“{0}, {1}”, url, name));
}

public static string GetFormsServerUrl(SPListItem item)
{
return (item.Web.Url + “/_layouts/FormServer.aspx?XmlLocation=” + HttpUtility.UrlEncode(item.Web.ServerRelativeUrl) + “/” + HttpUtility.UrlEncode(item.Url) + “&OpenIn=Browser”);
}

Working from the bottom up, the GetformsServerUrl takes in the item you want the forms server URL for.  It does this by referencing the formserver.aspx and providing the correct parameters.  Above that CreateURLFieldString takes in the URL and a text description to create the string that you have to put into the field.

The actual MethodInvoking event for the createTask activity calls GetFormsServerUrl to get the actual URL and then CreateUrlFieldString to create a meaningful description for the link.  It then uses the SPBuiltInFieldId to get the Guid for the WorkflowLink field.

The net is a link that displays with a customized message and opens in the browser.

6 Comments

  1. Thanks a lot!
    Exactly what I needed.

  2. Hi, the idea and the post is fine, but this does not work for me fully: the “displayed” link is fine, but the HREF in the anchor tag in the email still contains the URL w/o the OpenIn=Browser parameter. Any idea what can be wrong? I have MOSS2007 Std + SP1. Thx

  3. Hi,

    how can i change the code where is the location

  4. I have the same issue as Tibor, Sharepoint is ignoring any link we pass to it. Tried passing Google as the URL and it still used the default link to the form. Is the URL for SPBuiltInFieldId.WorkflowLink ReadOnly?

  5. I don’t know If I said it already but …Excellent site, keep up the good work. I read a lot of blogs on a daily basis and for the most part, people lack substance but, I just wanted to make a quick comment to say I’m glad I found your blog. Thanks, :)

    A definite great read..

  6. May I ask where I go to change the code. I need to change it so that the email link opens the form in the web browser.

    Thanks in a million!

    Len


Leave a Reply to Assuttgeoto Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share this: