All about the Strategy, Design, Customisation, Deployment and Development of SharePoint and its related Technologies

  Administration   All Me!! Baby!!   Business   CKS   CQWP   Development   Duffer Moments   Email   Errors   Family   Fixes   General   Groove   How To   How To Code   InfoPath   IRM   Longhorn   Lotus Notes   Migration   Mobility   Office System 2007   Personal Projects   Records Management   Search Server   Security   SharePoint   Silverlight   SQL   Tech Ed 2008   Testing   Vista   VSTO   WSS   XSL

[25/09/2007] MOSS2007 – Show InfoPath fields within CQWP (well attempt to)
 
Categories: Development, Office System 2007, SharePoint, InfoPath
 

I recently got asked a question regarding the viewing of InfoPath properties and fields within a CQWP. The question was specifically to do with "Administrator Approved" forms. Within MOSS2007 when you create a form you can either publish it to a document library, site content type or as an administrator approved form. When you publish the form you are able to specify what fields if any are promoted and become visible within the sites and libraries in SharePoint. In this post we will look at creating a very basic InfoPath form and then get the field values to render within a CQWP. Firstly we will look at creating a simple form. To do create the form you want and then select the "File, Publish" option. The following wizard will appear:

For the first example we will look at publishing it to a content type. To do this; follow the wizard.

Make sure that you save the form to a generic location. In this example it will be saved to the "Form Templates" library within SharePoint.

Once this form has been saved, you know have to select the fields that you want to promote to the sites and lists.

Remember to rename column name that gets added here so the spaces are removed. If you do not then you need to call these fields in this format: Demo_x0020_Full_x0020_Name

Once this is published a new content type will be created with its associated content type as well as the form being published. Now that we have it setup we can simply consume these using the CQWP. To do this you will need to export the web part down and modify the "CommonViewFields" parameter as shown below.

Now we have added the fields to render; we also need to make the same changes to the "ItemStyle.xsl" so the fields can be rendered by the style. The style I am using is shown below:

Once the web part is added to the main page and the style applied it should render the fields from the InfoPath forms that were promoted to the site content type.

Ignore the format above; this is just a demo to show the fields being rendered. Now that this works when we publish the form as a content type I wanted investigate how this would work if the form was "Administrator Approved". To do this I republished the form this time slightly different than before.

Notice that I have changed the field's names to the above so they don't conflict with the original ones from before.

Now that the form has been published ready for "Administrator Approval" we need to open up application management within central administration and click the "Manage Form Templates" option. Once here we need to upload the form.

Once the form is uploaded, it needs to be activated to a site collection. To do this select the menu item on the context menu for the item.

The approval process not only publishes the form but creates a content type and all the site columns associated with it.

At this point all we need to do is modify the CQWP "CommonViewFields" and the "itemstyle.xsl" style so that the web part renders the correct columns. The "CommonViewFields" should be as listed below:

The style code should also be modified as below:

When we now add the web part and view it, it should look as shown.

I was a little confused as to why the other columns did not appear in the CQWP. After further investigation I noticed that the columns were not actually called the names listed above. If you access the site column administration screen and click the specified columns you can find out the actual name.

The field name looks exactly as we would expect, but if we look at the URL in the browser it is different.

http://intranet.labs.local/_layouts/fldedit.aspx?field=e21843e8%2Dcd45%2D4185%2D88a0%2D368251a2382c&Source=%2F%5Flayouts%2Fmngfield%2Easpx%3FFilter%3DAll%2520Groups

According to this URL the field name is "e21843e8%2Dcd45%2D4185%2D88a0%2D368251a2382c". So I thought this is simple just change all the names to match the correct string. Looking in the string I assumed that the "%2D" was actually the ASCII code for "-". However after testing this it does not work either. After having a chat with "Joris Poelman" a fellow MVP, he states in his article found in the Real World SharePoint 2007 book that the internal name could look like the following:

"_x007b_ e21843e8_x002d_cd45_x002d_4185_x002d_88a0_x002d_368251a2382c_x007d_"

So after some investigation I tried to replace all the "%2D" values and the start and end with the same as above but no avail. I then realised that to find the internal name of a field I would need to use CAML code. So I opened up the CAML Query tool from U2U and connected to my site.

Once connected to my site the tree view on the left gets populated. I then clicked on the item needed in this case I chose the "DocLib".

I then selected the "DemoFullNameAdministratorApproved" field and selected the following parameters.

When the field is then added we find the internal name of the field is:

Now that we have found the internal field names we can simply change our CQWP and style to match this. Before I did this I used a simple windows application I use for testing CAML queries. The query looked as below:

Using the "SPSiteDataQuery" in code I was able to run this CAML and return a simple XML string shown below. This meant that we should be able to add this to the CQWP and it should render the items we want.

Now that we know what the CAML query and field names are we can in theory just drop this into the CQWP in the relevant properties and it *should* render as we want. The following changes were made:

CommonViewFields

 

ViewFieldsOverride

 

ListsOverride

 

QueryOverride

Now the CQWP is configured the "ItemStyle.xsl" needs modifying. The changes I made here were:

After all this!! Upon adding the modified CQWP and adding the custom style it still only rendered the "Title" and not any of our custom properties. I am still investigating this as it would be great to get to work properly. At this moment in time I am investigating the relationship between the field references within the CQWP and the "ItemStyle.xsl". Hopefully I will be able to come back to you with the answer, and hopefully it won't be "writing a custom web part" using the "SPSiteDataQuery" provider. J

 
3 Comments
 

Comments

Wednesday, 26 Sep 2007 10:28 by Tobias Zimmergren
Hey Liam.

This is an awesome post. I might just have to referr to it in the MOSS 2007 Development course I'm tutoring next week :)

Wednesday, 26 Sep 2007 08:23 by Adri Verlaan [MSFT]
I would suggest using the DataColumnRename property of the CQWP, since it can be quite frustrating trying to figure how the XSLT engine translated the SharePoint internal name.

here a snippet of XSL that can give you what data is sent:
<xsl:for-each select="@*">
  Name:<xsl:value-of select="name()"/>
</xsl:for-each>

Thursday, 27 Sep 2007 07:53 by Liam Cleary
Thanks for the tip Adri, much appreciated and exactly what I was after :-) I have now posted part two with the answer. Part three to come. http://www.helloitsliam.com/archive/2007/09/27/moss2007-–-show-infopath-fields-within-cqwp-yes-you-can.aspx

Name:

URL:

Email:

Comments: