2011 February

Rendering html in a SharePoint Dialog requires a DOM element and not a String

Most of the examples of using dialogs in SharePoint refer to calling other pages, effectively creating a popup iframe. This approach is both useful and reasonably well documented (Charlie Holland’s blog has the best examples I’ve seen to date).

 

<script>

	function ShowDialog()
	{
		var options = {
			url: 'http://www.google.com',
			autoSize:true,
			allowMaximize:true,
			title: 'Test dialog',
			showClose: true,
		};
		var dialog = SP.UI.ModalDialog.showModalDialog(options);
	}

</script>

<a href="javascript:ShowDialog()">Boo</a>

What isn’t well documented is using SharePoint modal dialogs to render dynamically generated html. When you call SP.UI.ModalDialog.ShowModalDialog you need to pass in a SP.UI.DialogOptions object. Charlie kindly posted the list onto MSDN, but with regards to passing in html it’s incorrect. It seems to indicate that raw html can be passed in.

<script>

	function ShowDialog()
	{
		var htmlString = 'hello world';

		var options = {
			html: htmlString,
			autoSize:true,
			allowMaximize:true,
			title: 'Test dialog',
			showClose: true,
		};

		var dialog = SP.UI.ModalDialog.showModalDialog(options);
	}

</script>

<a href="javascript:ShowDialog()">Boo</a>

 

However if you try this you’ll just get an error like this:

 

Message: Object doesn't support this property or method
Line: 2
Char: 18225
Code: 0
URI: http:///_layouts/sp.ui.dialog.js?rev=IuXtJ2CrScK6oX4zOTTy%2BA%3D%3D

 

This is because the string that gets passed in is evaluated for nodeType (if you want to check for yourself, see around line 764 in SP.UI.Dialog.debug.js, there is a function that the html string is passed into with a definition that looks like $13_0: function($p0).

 

What this means is that you have to pass in a DOM element.

 

<script>

	function ShowDialog()
	{
		var htmlElement = document.createElement('p');

		var helloWorldNode = document.createTextNode('Hello world!');
		htmlElement.appendChild(helloWorldNode);

		var options = {
			html: htmlElement,
			autoSize:true,
			allowMaximize:true,
			title: 'Test dialog',
			showClose: true,
		};

		var dialog = SP.UI.ModalDialog.showModalDialog(options);
	}

</script>

<a href="javascript:ShowDialog()">Boo</a>

Do that, and you’ll get your dynamic-html dialog!

 

 

By admin on February 26, 2011 | Ajax, Design, sharepoint2010 | 6 comments

Debugging FAST for SharePoint : Part 1 – the QRServer

With FAST for SharePoint being so new, it’s difficult to know how to work with the product when it comes to debugging. There are many different questions:

  • What does it know about document x?
  • What is FAST returning to my SharePoint server?
  • What is the rank of a certain document?
  • What is SharePoint asking FAST?
  • Why aren’t User Contexts working? Are User Contexts working?

For all of these questions, the QRServer is an invaluable tool.

What is the QR Server?

The Query Result (QR) Server, is a way to speak with FAST directly, without worrying about SharePoint. It’s a web site, accessible only to users logged in to the FAST server that allows users to fire queries into FAST and see the resulting XML. This is important because it allows users to rule-out (or in) SharePoint as the culprit for broken searches.

By default, the QR Server respects content security rules, so using different accounts on the QR Server will give you different results.

How do I find my QR Server?

You access the QR Server via a web-browser. The url to type is http://<fastservername>:<basePortNumber+280>/. So let’s say the ever popular contoso.com is served by a FAST server with the name http://fsContoso1.controso.com using the default base port number of 13000. In that case you’d need to navigate to http://fsContoso1.controso.com:13280.

The QR Server is ONLY accessible directly from a FAST server, so you must Remote Desktop onto the server to use it. From there, you find your base port number by looking at the hostconfiguration.xml in the < FASTInstallLocation>/etc/ folder


The FAST Query Game

Debugging queries in a production or UAT environment is a serious pain. This technique was taught to me by a FAST Ninja (thanks Torstein!) and is a bit bizarre. It involves running a query from SharePoint and then extracting the data passed to FAST out of a log file and manually resubmitting the query on the FAST server, all within 15 seconds.

This approach is necessary because along with your query, SharePoint sends FAST  a user authorization token that is only valid for a short period of time.

Preparation:

  • You must be logged into the FAST server
  • Open Windows Explorer and navigate to <FASTInstallLocation>/var/logs/querylogs/. Find the most recently modified file.
  • Open a copy of NotePad (or your favourite text editor)
  • On the FAST server, open a web browser and navigate to the QR Server.
    • Search for the term “test”
  • Anywhere
    • Open a web browser and navigate to the SharePoint search UI.
  • At this stage you will have 1x Notepad, 1x Windows Explorer, 2x Web browsers

The rules:

  • You must execute your queries from the SharePoint server, via the UI
  • You have 15 seconds to complete the following process… or you die… probably.

STEP 1: On your SharePoint FAST Search Centre, execute your query

STEP 2: Quickly switch to the FAST server and into the the FAST log folder. Open the most recent log file in Notepad and navigate to the bottom, making sure Word Wrap is on.

STEP 3: Take the last url in the file

You will need to grab the url from the  querystring, taking everything after “search?” until the HTTP/1.1 text. In a production environment this can span multiple lines and be tricky to select within the 15 second limit. This is usually the part where I run out of time.

STEP 4: On the QR Server, paste the querystring into the location noted below

STEP 5: Hit “go”, “enter” or whatever to start your search and see the results FAST sent back to SharePoint

If you run out of time, you’ll see the same QUERYTRANSFORMS elements, but nothing else.

Interpreting the results

Following a successful round of the FAST Debugging game, you can investigate the results. I can’t possibly describe each element, but at a high-level:

  • QUERYTRANSFORMS à Describes what was submitted through SharePoint. Refiner selections, user contexts, sorting selections will all appear here.
  • NAVIGATION à Indicate what refinement data is being sent back to the server. Useful when the number of displayed refiners seems incorrect.
  • RESULTSET à Includes all the search hits from the current “page”, including the value of every managed property (i.e. attributes of a document that FAST gives special treatment). While it doesn’t give you a way to interrogate every crawled property you also get to look at the rank of a document
  • PAGENAVIGATION à If you work in Collaboration you’re smart enough to figure this out.

I’ll talk more about interpreting the results in my next post, but for now, I hope this helps.

Cheers!

Neil

By admin on February 3, 2011 | FAST, Sharepoint | 4 comments