![]() |
Enterprise Systems »
SharePoint Server »
General
Intermediate
License: The Code Project Open License (CPOL)
MOSS 2007 Department and People Viewer Part 1/2By Dietmar KurokShowing People grouped by departments in an own style (XSLT) and without limits in count of results and paging. Only intensively using build-in Webparts. |
Javascript, XML, CSS, SQL, HTML, XSLT, Office, ASP.NET, IE 6.0, IE 7, Dev, Design, SysAdmin
|
||||||||
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
A few weeks ago I was asked to prepare a list of employees working in different departments, but summarized in one head-departement. This list should reside on a Webpart-page of the head-department. The layout should be in many parts different from the standard-layout which People Search Core Result (PSCR) gives and it should fight against some limits that are build into PSCR.
These limits are:
Additionally I have some other restrictions which, I think, many normal users in bigger, productive MOSS 2007-environemts have:
But fortunately I'm allowed to use Microsoft's Office SharePoint Designer 2007 and I have a fair knowledge of SQL, XML and XSLT!
So I'm gonna present you the result of my many trial and error roundtrips and a bunch of some tools (especially XSLTs) making the work easier for you.
I've divided this article into two parts becasue of my little spare time for writing it.
This first part gives you directions on how to get the data with the help of SharePoint's webservices.
The second part (coming soon) will provide you with some enhanced XSLT to format, page and group these data.
After many trials to tune PSCR getting my wishes done, I decided that the only way to get arround the hardest limit, the 50 records per roundtrip, is to use a very basic, but always available webpart: WebPartPages:DataFormWebPart. This one is a very basic one, but has the advantage that you can influence it on your own.
DataFormWebPart can retrieve data from various <DataSources>. For receiving people-data I decided to use one of SharePoint's webservice-methods. You can look up search-methods by browsing to http://yoursharepointserver/_vti_bin/search.asmx . The method we need for getting people-information is the QueryEx-method with a parameter queryXml.
A valid parameter-XML looks something like this:
<QueryPacket xmlns="urn:Microsoft.Search.Query" Revision="1000">
<Query>
<Context>
<QueryText language="en-US" type="MSSQLFT">SELECT PreferredName, Department, Manager, AboutMe,
Title, Path, Description, Write, Rank, Size FROM SCOPE() where "scope"='People'
AND Department LIKE 'MAN DEP 1'</QueryText>
</Context>
<Range>
<StartAt>1</StartAt>
<Count>1000</Count>
</Range>
</Query>
</QueryPacket>
A detailed description of the QueryPacket-syntax can be found here:Also interesting is the <Range>-element: <Start> determines from which position on the result will be returned; <Count> gives the number of results returned. My hardest limit and my motivation for doing this work was the "50-record per roundtrip"-limit; so here we can bypass that limit. It's up to you to make this number a high a you like; the default is 100.
But some questions will arise now to you:
1) The query returns XML (Surprised? - No, not really). This makes absolutly sense, because then we can render it by using XSLT.
2) A list of properties supported by your Shared Service Provider / MOSS 2007 can be obtained by another method of the same webservice: GetSearchMetaData (see below on how to view also these information on a SharePoint weppart-page)
3) Yeah, this is the most "frustrating" part in it, because IMO SharePoint Designer doesn't support this kind of work very well! But it works.
Because most times I want first to have the data and afterwards I pay attention to the formatting, I used this XSLT whereever I wanted to see what comes back from my query (see file ShowAllXML.xslt):
<?xml version="1.0" encoding="utf-8"?>D
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xmp>
<xsl:copy-of select="*"/>
</xmp>
</xsl:template>
</xsl:stylesheet>
This XSL just takes the input XML and render it back like XML; xsl:copy-of select="*" takes every node in the XML and gives it back; the surrounding <xmp>-tags give the information to the browser, that it should be treated like text (and not like tags, because then we would only see the parts of the input-XML which are not tags).
Inside SharePoint/MOSS 2007 XSL is used in the following way:
So, whenever you use now webservices inside your SharePoint-pages, use this simple XSL to first look what data you really get. And, another advantage: you can copy the rendered HTML, which is shown like XML, to your XSLT-tool as an input-file for testing the XSL.
If you don't have any XSLT-tool, you can alos use Internet-Explorer's build-in XSLT-processing capability by referencing the XSLT-file (XSLTFileTableView.xslt in my example here) which IE shall use to show your XML:
<?xml version="1.0" encoding="utf-8"?>
<!--Referencing the correct XSLT to use-->
<?xml-stylesheet type="text/xsl" href="XSLTFileTableView.xslt"?>
<All_Results>
....Rest of your XML...
</All_Results>
So, where are we now?
We got:
- some parts of the needed data (maybe not all the properties you like to see)
- a way to look into the data in SharePoint-Designer
- a way to render the data as xml in our webpart-page
What's missing:
- a list of properties we can fetch (the "columns" of the MSSQLFT)
- some really good formatting with grouping and paging
As mentioned above, the webservice-method GetSearchMetaData gives the information about the available properties for the QueryEx-method. So just put another DataFormWebPart to your search-page (or create a nwe page and insert it there), create a new connection to the search.asmx of your site and now use the GetSearchMetaData instead of the QueryEx-method. Save the webpage, modify the webpart and copy the XSL of ShowAllXML.xslt (see above) into the XSL-editor of your webpart's properties. As a result you get an XML showing you the SearchMetaData of your site. Each managed property is one of these elements:
...
<Properties diffgr:id="Properties68" msdata:rowOrder="67" diffgr:hasChanges="inserted">
<Name>Manager</Name>
<Description />
<Type>System.String</Type>
<Retrievable>true</Retrievable>
<FullTextQueriable>false</FullTextQueriable>
</Properties>
...
The <name>-element gives you the name that you can use in your MSSQLFT-query of the QueryEx. I cannot provide you a full list of the properties because they are dynamically / configurable on the SharePoint-Shared Service Provider. What I've mentioned in our environment is, that for the people-properties which shall be exposed to the query-service, there is a need for indexing them. So if you're missing a property in your list, the chance is good to ask your SharePoint-admin to set the property to "indexed" in the people-import properties of the Shared Service Provider (your admin will know where to find it :-) )
The list of properties may be horrible long and may miss descriptions. So you will have to filter them somehow. Becasue I hate to copy&paste the names out of the XML into the QueryEx-Expression-XML, I did the following:
<?xml-stylesheet type="text/xsl" href="PropertiesAndScopesToQueryPacketIE.xslt"?>
Take care of the following when using this:
where "scope"='People' AND . After the AND insert your own where-criteria; you can use any criteria in the where-part provided that you've included the property in the select-part (so you shouldn't have it commented in the steps before)Title, Path, Description, Write, Rank and Size (see http://msdn.microsoft.com/en-us/library/ms543175.aspx)So you should now have the wished people-records with the properties you want in XML-format, and NOT limitted to 50 records.
The second part of this article will then give you a guide on how to format, group and paging this result with the help of XSLT. Stay tuned!
This is the first version of this article.
| You must Sign In to use this message board. | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 24 Jun 2008 Editor: |
Copyright 2008 by Dietmar Kurok Everything else Copyright © CodeProject, 1999-2009 Web16 | Advertise on the Code Project |