Alert Me: Parameters Passed to SearchAlertType.GetAlertCreationLink()

 

The SDK documents the GetAlertCreationLink() method as part of every class in the Microsoft.SharePoint.Portal.Alerts namespace.  However, if we want to utilize this method in some way -- for example, to generate our own "Alert Me" link on a custom search page -- the documentation is not quite sufficient.  Here's how the SDK defines the parameters passed to GetAlertCreationLink for the SearchAlertType class:

 

strQueryWhereClause WHERE clause for the search query this alert describes.

strViewThisSearchResultsURL URL for the search result that this alert describes.

strSuggestedTitle Suggested link text.

strXMLEditQueryData XML representation of the edit query data.

 

The first three of these I can figure out just fine.  The fourth, though, is pretty cryptic.  What exactly does "XML representation of the edit query data" mean?  How am I supposed to write any sort of "representation" if I haven't been given an example of the format?

 

Well, if we get sneaky and look around a bit, we can find the format hiding in the HTML source.  Here's how.

 

Let's do a search (in my case, I'm searching the portal for "test").  When we get the results, an Alert Me link will be on the left-hand pane.  Like a good sleuth, I'm going to "View Source" in IE.  The HTML source for the Alert Me link looks like the following (FIND: Alert Me):

 

<a id="_ctl7:sch_mgmt_subs" class="" href="javascript:schOnSubscribeSearch();" mce_href="javascript:schOnSubscribeSearch();" accesskey="u" title="To be notified when new results are available or existing results change">Alert Me</a>

 

Alright.  Now we're getting somewhere.  The link calls a JScript -- I know it says javascript, but I'm sure they meant to say JScript, right? :) -- method schOnSubscribeSearch().  Another hunt through the HTML source yields this function (FIND: schOnSubscribeSearch):

 

function schOnSubscribeSearch()

{

window.location.href = "javascript:spslcLBP\(&#39;&#39;,&#39;&#39;,&#39;Search&#39;,&#39;&#39;,&#39;

http:\\\/\\\/sharepointblank\\\/Search.aspx?k=test&amp;s=All%2520sources&#39;,&#39;test&#39;,&#39;

Search for \\&quot;test\\&quot;&#39;,ax0\(\)\);";

}

 

Sweeeet.  Now, that's some good looking stuff.  If we get rid of some encoding, these parameters look something like:

 

spslcLBP("",

"",

"Search",

"",

"https://sharepointblank/Search.aspx?k=test&s=All sources",

"test",

"Search for "test"",

ax0());

 

Some more hunting, and I can find the spslcLBP function, in linkcreator.js.  Its parameter list looks like this:

 

function spslcLBP(

oItem,

sUrl,

sAlertType,

sObjectDefinition,

sObjectUrl,

sObjectDisplay,

sSuggestedTitle,

sXmlParameters)

 

A bit more looking into the HTML/JavaScript source, and I can determine that the last of these parameters is what I'm looking for -- in otherwords, if I can find what sXmlParameters looks like, I know what strXMLEditQueryData parameter should look like.  In my spslcLBP that got rendered to the page, the sXmlParameters parameter is "ax0()".  This looks like another JScript function, so here I go searching through the HTML source of the page again (FIND: ax0()), and I find the culprit:

 

<SCRIPT DEFER>function ax0() { return 'PFNlYXJjaE9wdGltaXphdGlvbj48

VGVybXM+dGVzdDwvVGVybXM+PFF1ZXJ5SW5mbz4gDQooKCJ1cm46c2N

oZW1hcy1taWNyb3NvZnQtY29tOnB1Ymxpc2hpbmc6SG9tZUJlc3RCZXRLZ

Xl3b3JkcyI9IHNvbWUgYXJyYXkgWyd0ZXN0J10gUkFOSyBCWSBDT0VSQ0l

PTihhYnNvbHV0ZSwgOTk5KSkNCk9SIChGUkVFVEVYVCgidXJuOnNjaGVtY

XMtbWljcm9zb2Z0LWNvbTpzaGFyZXBvaW50OnBvcnRhbDpwcm9maWxlOl

ByZWZlcnJlZE5hbWUiLCAndGVzdCcpIFJBTksgQlkgQ09FUkNJT04obXVsdGl

wbHksIDAuMDEpKQ0KT1IgRlJFRVRFWFQoI1dlaWdodGVkUHJvcHMsICd0ZX

N0JykgKQ0KIA0KICA8L1F1ZXJ5SW5mbz48L1NlYXJjaE9wdGltaXphdGlvbj4

=';}</SCRIPT>

 

Very nice.  Base64-encoded data.  Let's decode that bad boy and see what happens.  Once decoded from Base64, it looks like this [I've formatted with line breaks/indents]:

 

<SearchOptimization>

  <Terms>test</Terms>

  <QueryInfo>

    (("urn:schemas-microsoft-com:publishing:HomeBestBetKeywords"= some array ['test'] RANK BY       COERCION(absolute, 999))

OR (FREETEXT("urn:schemas-microsoft-com:sharepoint:portal:profile:PreferredName", 'test') RANK BY COERCION(multiply, 0.01))

OR FREETEXT(#WeightedProps, 'test') )

  </QueryInfo>

</SearchOptimization>

 

So, there's our format.  As regards the GetAlertCreationLink() method of the Microsoft.SharePoint.Portal.Alerts.SearchAlertType class, the fourth argument, strXMLEditQueryData, should have the following format:

 

<SearchOptimization>

  <Terms></Terms>

  <QueryInfo></QueryInfo>

</SearchOptimization>