none
Why do we need Common view fields in content query web part?

    Question

  • I am a bit confused on the purpose of "CommonViewFields" in CQWP.

    Almost all the write-ups on the web says that if we need a custom column to be available in the web part's XSL, we need to export the webpart file, add the columns to "CommonViewFields", import the web part to the site.

    However I noticed that, when I create a custom style template in my "ItemStyle.xsl" and simply add a line like <xsl:value-of select="@MyCustomColmn"/>, then "MyCustomColumn" appears automatically under "Fields to display" in the tool pane as a text box prompt, when I edit the web part and select my style template. I can then simply fill-in my column display name under "MyCustomColumn" and the web part works perfectly fine. (There is NO NEED to export the web part, edit the ".webpart" file and add "commonviewfields" etc..etc..etc)

    If this works, then what is the real need for "commonviewfields" ?

    Can someone shed light on this? I am totally confused.. (SharePoint 2010)

     

     

     

     

     

    Saturday, September 04, 2010 12:19 PM

Answers

All replies

  • The behavior you're describing is new to SharePoint 2010. In SharePoint 2007 the only way to include custom fields in CQWP was to add them to the CommonViewFields property. So if you're working with SharePoint 2010 you don't have to export the CQWP to add new fields no more.


    w: http://blog.mastykarz.nl | t: @waldekm | c: http://mavention.codeplex.com | c: http://mavention.nl
    Saturday, September 04, 2010 1:53 PM
  • Thank you very much, Sir.

    I did not find that information anywhere and hence the confusion.

    It would have helped if MS had mentioned it here http://msdn.microsoft.com/en-us/library/ms497457.aspx

    The above link says,

    "By default, the XSL style sheet that controls the presentation of the Content By Query Web Part renders the Title, Description, ImageUrl, and LinkUrl columns (if present) of the items that the query returns. The Web Part renders the ImageUrl column and the LinkUrl column as an image and as a hyperlink, respectively. The Content By Query Web Part uses XSL style sheets to render these columns by default.

    If  you want to query for custom content types and render specific columns from those content types in the Web Part, you must perform some minor customization in the .webpart file."

    I had needlessly exported about 12 web parts in my project, until I found this behavior by chance. Now I have to change them all again. :(

     

     

    Saturday, September 04, 2010 2:08 PM
  • Thank you very much, Sir.

    I did not find that information anywhere and hence the confusion.

    It would have helped if MS had mentioned it here http://msdn.microsoft.com/en-us/library/ms497457.aspx

    The above link says,

    "By default, the XSL style sheet that controls the presentation of the Content By Query Web Part renders the Title, Description, ImageUrl, and LinkUrl columns (if present) of the items that the query returns. The Web Part renders the ImageUrl column and the LinkUrl column as an image and as a hyperlink, respectively. The Content By Query Web Part uses XSL style sheets to render these columns by default.

    If  you want to query for custom content types and render specific columns from those content types in the Web Part, you must perform some minor customization in the .webpart file."

    I had needlessly exported about 12 web parts in my project, until I found this behavior by chance. Now I have to change them all again. :(

     

     

    I think documentation is a vague afterthought for Microsoft when it comes to Sharepoint. Much of it appears to be shrouded in mystery.
    Monday, September 13, 2010 10:37 PM
  • Does this work for custom content types as well?
    Chris Stewart
    Monday, November 29, 2010 4:18 PM
  • Karthik,
          Sure just looking at CQWP in 2010 you said you created an itemstyle.xsl where these xsl files and where do you add the <xsl:value-of select="@MyCustomColmn"/>,  is it in the  itemstyle.xsl.

    Does this mean i can have different ItemStyle for different webparts.
    Can you explain in detail how to in SP 2010?
    Cheers

    Wednesday, May 25, 2011 5:29 AM
  • Thanks guys and to Karthik for bringing that up and Waldek for clarifying! I was also confused so much about this.MSDN article says its for sharepoint 2010(http://msdn.microsoft.com/en-us/library/aa981241.aspx) which rediculous.

    For 2010 we dont need to export/import webpart, just custom style is all that is needed.

    Patrick- I am not sure if you are still looking for an answer, but yes you can have as many styles as you need, just add one Template(Copy exiting and modify) for whatever fields you want to display in the ItemStyle.xsl file.

    One more note guys, there is also no need to modify header.xsl or ContentQueryMain for adding header , you can just do that in your template in ItemStyle.xsl. http://sharepoint-guru.blogspot.com/2007/08/adding-table-headers-andor-footers-to.html

    So, all you need to do customize CQWP is add your template in the itemstyle.xsl, thats all!!

     

    Tuesday, November 29, 2011 6:36 PM
  • Agree,  http://msdn.microsoft.com/en-us/library/aa981241.aspx) is absolute rediculous!!!!

    I think template mode is the only one to use in Sharepoint 2010. I'll try.

    Ah... Microsoft Microsoft... do less and better please..

    Monday, December 12, 2011 3:57 PM