forge

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 replies
  1. Tibor SAS
    Tibor SAS says:

    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

  2. Graham Davis
    Graham Davis says:

    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?

  3. Assuttgeoto
    Assuttgeoto says:

    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..

  4. Lenramilos
    Lenramilos says:

    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

Comments are closed.