MOSS 2007 – Workflow – InfoPath Form Associated
April 15, 2008 at 2:44 pm 10 comments
It’s pretty simple to create a SharePoint workflow using Visual Studio and InfoPath (for the forms). Take as a sample the “approval” one provided with MOSS.
When a task is created by the workflow, it’s stored in the associate task list. When we click on it, it’s redirect to the “WrkTaskIP.aspx” that displays the task form. This page used the “XmlFormView” to display the associated task form:
Remark: All these steps are not addressed in this post.
A document library storing Infopath Forms is associated to the workflow. On the site library advanced settings, the “Display as Web page” functionality is activated.
Settings:
Opened form:
That means the InfoPath forms are opened inside the web explorer using the “Forms Service”. Imagine that the workflow has been started and one task has been created. When clicking on the task link, the “WrkTaskIP.aspx” is displayed for the approval process. On this page, a link to the targeted document exists:
When clicking on this link, we expect to see the form opened by the browser. It’s not the case and it’s a simple link to the document. The InfoPath client application is started instead of the browser:
Issue
This is the issue. This page doesn’t look at the source library settings in order to update the link and displays as expected a URL like:
http://vpcmoss/_layouts/WrkTaskIP.aspx?List=b3983e69%2D71c0%2D4348%2Db22b%2D5ae09f686b29&ID=1
Solution
No it’s time to find a solution. The first reflex is use our favorite search engine. The result is that there are not so many answer. Maybe there is another solution existing on the web but anyway, this post shows a global approach on “how find solution on SharePoint“.
Step 1
First we need to understand how is working the “WrkTaskIP.aspx” page to build this link. Start by opening this page to look at the HTML and page directive.
2: <td width=”10″ valign=”center” style=”padding: 4px;”>
3: <img IMG SRC=”/_layouts/images/Workflows.gif” alt=<%SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode (GetLocString(“WrkTask_PageTitle”)),Response.Output);%>/>
4: </td>
5: <td>
6: <% 1: SPHttpUtility.NoEncode(m_pageDescription,Response.Output);
%>
7: </td>
8: </tr>
The HTML generated for the document link is stored in the “m_pageDescription” field (sooooooo lovely
).
Step 2
Next step, discover how the HTML data is generated. As many people said, Reflector is our friend. We looked at the aspx page directive to find the associated class:
<%@ Page Language=”C#” Inherits=”Microsoft.Office.Workflow.WrkTaskIPPage“
We open Reflector and look at this class. All the code is in the “OnLoad” method.
Reflector view:
The HTML link building:
Step 3
We just have to create a copy of the “WrkTaskIP.aspx” page, update the code. We can use the code below:
2:
3: try
4: {
5: // Get SPListItem source
6: using (SPWeb web = SPContext.Current.Web)
7: {
8: SPList taskList = web.Lists[new Guid(Request["List"])];
9: SPListItem item = taskList.GetItemById(int.Parse(Request["ID"]));
10:
11: Guid workflowGuid = new Guid((string)item[SPBuiltInFieldId.WorkflowInstanceID]);
12:
13: SPWorkflow workflow = new SPWorkflow(web, workflowGuid);
14:
15: SPListItem sourceItem = workflow.ParentItem;
16:
17: //Build HTML Link header
18: if (sourceItem == null)
19: {
20: linkHTML = “No item associated”;
21: }
22: else
23: {
24: StringBuilder tmp = new StringBuilder();
25: tmp.Append(“This workflow task applies to “);
26: tmp.Append(“<a href=\”");
27:
28: // Build href
29: string href = string.Format(“{0}/_layouts/FormServer.aspx?XmlLocation=/{1}&Options=DisableSave&DefaultItemOpen=1″,
30: web.Url, sourceItem.Url);
31:
32: tmp.Append(href);
33: tmp.Append(“\”>”);
34:
35: tmp.Append(sourceItem.Title);
36: tmp.Append(“</a>”);
37:
38: linkHTML = tmp.ToString();
39: }
40: }
41: }
42: catch (Exception ex)
43: {
44: linkHTML = “Error when retrieving item source”;
45: }
46: // Update page
47: m_pageDescription = linkHTML;
48:
Step 4
We need to replace the “WrkTaskIP.aspx” by the created one when clicking on the task. This can easily be done using a “ContentType” and by updating the xml workflow file.
New updated task “ContentType”:
2: <Elements xmlns=”http://schemas.microsoft.com/sharepoint/”>
3: <ContentType ID=”0x01080100C9C9515DE4E24001905074F980F93151″
4: Name=”WorkflowTaskIP2 ContentType”
5: Description=”OHCHR ContenType associates to the task Workflow”
6: Group=”_Hidden”
7: Hidden=”TRUE”
8: Version=”0″>
9: <FieldRefs>
10: </FieldRefs>
11: <XmlDocuments>
12: <XmlDocument NamespaceURI=”http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url”>
13: <FormUrls xmlns=”http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url”>
14: <Display>_layouts/WrkTaskIP2.aspx</Display>
15: <Edit>_layouts/WrkTaskIP2.aspx</Edit>
16: </FormUrls>
17: </XmlDocument>
18: </XmlDocuments>
19: </ContentType>
20: </Elements>
Update the workflow configuration file by updating the “TaskListContentTypeId” id.
2: Name=”WorkflowFeature”
3: Description=”"
4: Id=”71b980d7-69d8-4f86-8702-d472e9b00660″
5: CodeBesideClass=”[Your class]“
6: CodeBesideAssembly=”[Your assembly], Version=1.0.0.0, Culture=neutral, PublicKeyToken=68985c29fbcd9e0e”
7: TaskListContentTypeId=”0x01080100C9C9515DE4E24001905074F980F93151″
8: AssociationUrl=”_layouts/CstWrkflIP.aspx”
9: InstantiationUrl=”_layouts/IniWrkflIP.aspx”
10: ModificationUrl=”_layouts/ModWrkflIP.aspx”
11: StatusUrl=”_layouts/WrkStat.aspx”>
12:
13: <Categories/>
14: <!– Tags to specify InfoPath forms for the workflow; delete tags for forms that you do not have –>
15: <MetaData>
16: <!– <Association_FormURN>associationFormURN</Association_FormURN>
17: <Instantiation_FormURN>instantiationFormURN</Instantiation_FormURN>
18: <Task0_FormURN>taskFormURN</Task0_FormURN>
19:
20: <Modification_GUID_FormURN>modificationURN</Modification_GUID_FormURN>
21: <Modification_GUID_Name>Name of Modification</Modification_GUID_Name>
22: –>
23: <AssociateOnActivation>false</AssociateOnActivation>
24: </MetaData>
25: </Workflow>
Step 5
The last step is to encapsulate these modifications using a solution (wsp file) that will:
- Deploy your CententType feature
- Deploy your Workflow feature
- Copy the assembly to the GAC
- Copy the updated layout page
And that’s done !!!
To conclude on this post, when you need to develop something on SharePoint:
- looked at the existing SharePoint code
- use and reuse Reflector
Update: 05/03/2008
You can find below a link to the feature (part of the complete feature).
Hope that it’s not so bad for a first post
Entry filed under: InfoPath, SharePoint 2007. Tags: .
1.
sarah | April 30, 2008 at 9:24 am
I try the solution but I encountered an error when opening the task form. The new link displays fine but the form doesn’t display.
I think my updated code is not good.
Have you already test it. if so can you please give the all updated code ( in fact I have problem to arrange the native code copied from reflector)
2.
ntorrent | May 3, 2008 at 9:34 am
Yes this code is working as it’s used on an existing project.
The article has been updated and a link to the feature has been added.
3.
erhan | February 5, 2009 at 1:58 pm
thank you for this article. it’s work fine
4.
Sami Ullah Khan | February 6, 2009 at 11:01 am
Dear All,
Could any of one explain How to bring the WrkTaskIP.aspx page in the Refelector. Or if you are opening this dll (Microsoft.Office.Workflow.WrkTaskIPPage) where it resides.I am new to SharePoint ..Please help me out.
Thanks
5.
Sami | February 12, 2009 at 11:43 am
Dear ntorrent,
It would be much better if you could please explain how to deploy the above feature as solution in sharepoint .
Thansk
Sami
6.
Scott | March 3, 2009 at 9:28 pm
I’m getting an error:
The file ‘/_layouts/_layouts/application.master’ does not exist…
7.
Scott | March 3, 2009 at 10:01 pm
Resolved. I needed to register the namespace “Microsoft.SharePoint.Workflow” in my .aspx.
8. CleverWorkarounds » Sack Justin Bieber with SPD2010 and Forms Services – Part 1 | September 21, 2010 at 12:50 pm
[...] is generating the hyperlink to the original form. (Actually if you are a developer then check this excellent article for a deeper examination, albeit for SP2007). Now a developer could easily take a copy of this page [...]
9.
Levent | December 29, 2010 at 3:26 pm
Excellent post! I was searching for a solution for days now. In my opinion this is a HUGE oversight on behalf of Microsoft.
Thanks again!
10.
Dave Roberts | January 11, 2011 at 11:43 am
Thanks you soooo much really helpfull.
Dave