<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Richard Knudson&#039;s Dynamics CRM Trick Bag &#187; scripting</title>
	<atom:link href="http://www.dynamicscrmtrickbag.com/tag/scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dynamicscrmtrickbag.com</link>
	<description>Building business value on Dynamics CRM</description>
	<lastBuildDate>Fri, 27 Jan 2012 14:42:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Mashing up CRM and Twitter, Part 2</title>
		<link>http://www.dynamicscrmtrickbag.com/2009/03/16/crm-twitter-mashup2/</link>
		<comments>http://www.dynamicscrmtrickbag.com/2009/03/16/crm-twitter-mashup2/#comments</comments>
		<pubDate>Mon, 16 Mar 2009 17:42:36 +0000</pubDate>
		<dc:creator>Richard Knudson</dc:creator>
				<category><![CDATA[Customization]]></category>
		<category><![CDATA[Integration and SharePoint]]></category>
		<category><![CDATA[mashup]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.dynamicscrmtrickbag.com/?p=231</guid>
		<description><![CDATA[Learn how to do dynamic searches of Twitter Tweets based on information from a Dynamics CRM record.]]></description>
			<content:encoded><![CDATA[<h2>The Truth is Out There (in 140 Characters or less!)</h2>
<p>If you didn&#8217;t read the first part of this &#8220;series&#8221;, here&#8217;s a link to <a title="Part 1" href="http://www.dynamicscrmtrickbag.com/?p=124" target="_self">Mashing up CRM and Twitter, Part 1</a>. That article provides a high-level overview of three topics:</p>
<ol>
<li>What the heck Twitter is, in case you&#8217;re new to it</li>
<li>Why you might want to integrate it with Dynamics CRM</li>
<li>Some basics of Twitter Search</li>
</ol>
<p>To follow up on part 1, I want to cover two main topics here:</p>
<ol>
<li>How you can implement a managed Twitter search from a Dynamics CRM record</li>
<li>Discuss some of the interesting extensions of the simple example I&#8217;ll show, and argue a little more why Twitter search is so important</li>
</ol>
<h2>Implementing a Managed Twitter Search from Dynamics CRM</h2>
<p>What I&#8217;ll show here is some of the mechanics of doing a contextual Twitter search from a CRM record. These will be similar no matter what entity you&#8217;re searching from, so I&#8217;m going to show how to customize the Dynamics CRM &#8220;Competitor&#8221; entity. (In the example I show it will be not for my competitors, but for a group of companies that compete against <em>each other</em>. Same techniques, either way.)</p>
<p>The general technique is to use an IFRAME control on a customized CRM form, and dynamically update the &#8220;src&#8221; property of the IFRAME with information from the current record. Here&#8217;s what the user experience looks like, starting with the Competitor form opened to a specific record, in this case my favorite food company, Kraft:</p>
<div id="attachment_240" class="wp-caption alignnone" style="width: 451px"><img class="size-full wp-image-240  " title="comp_form1" src="http://www.dynamicscrmtrickbag.com/wp-content/uploads/2009/03/comp_form1.bmp" alt="&quot;Competitor&quot; form open with record selected" width="441" height="368" /><p class="wp-caption-text">Figure 1: Competitor form open with a record selected</p></div>
<p>This shows a standard Dynamics CRM form, in this case having double-clicked on the &#8220;Kraft&#8221; record from the Competitors grid. When a user clicks on the Twitter Search tab, what they see is an IFRAME that exposes the results of a Twitter search. What that might look like is shown here:</p>
<div id="attachment_241" class="wp-caption alignnone" style="width: 484px">
<h2><img class="size-full wp-image-241  " title="comp_form2" src="http://www.dynamicscrmtrickbag.com/wp-content/uploads/2009/03/comp_form2.bmp" alt="comp_form2" width="474" height="359" /></h2>
<p> </p>
<p><p class="wp-caption-text">Figure 2: Twitter search results based on CRM data</p></div></p>
<h2>How to Build it</h2>
<p>That&#8217;s the user experience. What I&#8217;ll show you next is how to build a customization like this &#8212; essentially, how to update the &#8220;src&#8221; property of an IFRAME like that with information from the current record. The idea here is to provide a managed search experience from within CRM, so my brand managers or whoever else might be using this don&#8217;t need to worry about Twitter search syntax. To save a little time, I&#8217;ll give you a &#8220;heuristic&#8221; step by step. I&#8217;ll post a video shortly where you can see all of the detailed steps, but for now&#8230;</p>
<p>&#8230;follow these steps:</p>
<ol>
<li>Customize the Competitors entity, by adding a tab, a section, and an IFRAME; call them all Twitter Search or something like that.</li>
<li>To start out, set the IFRAME&#8217;s URL property to <a href="http://search.twitter.com">http://search.twitter.com</a> . Turn off the &#8220;prevent cross-frame scripting&#8221; property by unchecking it.</li>
<li>Navigate to the form&#8217;s OnLoad event, and add the following  jscript code:</li>
</ol>
<p><em>code starts here:</em></p>
<p>var CRM_FORM_TYPE_CREATE = 1;<br />
var CRM_FORM_TYPE_UPDATE = 2;</p>
<p>var twittersearchURL = &#8220;&#8221;;</p>
<p>switch (crmForm.FormType)<br />
{<br />
 case CRM_FORM_TYPE_CREATE:<br />
    twittersearchURL = &#8220;<a href="http://search.twitter.com">http://search.twitter.com</a>&#8220;;  <br />
   break;</p>
<p> case CRM_FORM_TYPE_UPDATE:<br />
       // Use Twitter search with this account&#8217;s name when updating account<br />
  twittersearchURL = &#8220;<a href="http://search.twitter.com/search.atom?q">http://search.twitter.com/search.atom?q</a>=&#8221;;<br />
  // Encode the account name and add it to the search string<br />
  twittersearchURL += encodeURIComponent(crmForm.all.name.DataValue)+&#8221;&amp;rpp=100&amp;lang=en&amp;tude=:)&#8221;; <br />
  break;<br />
}</p>
<p>// Set the respective IFRAME&#8217;s URL<br />
//alert (twittersearchURL);</p>
<p>crmForm.all.IFRAME_twittersearch.src = twittersearchURL; </p>
<p><em>end of code </em></p>
<p>Let me make a couple of comments about this code, in case you want to try it or some variation on it:</p>
<ul>
<li>Notice that the twitter search url uses the &#8220;atom&#8221; qualifier. This is the way twitter search lets you return results in an RSS format. This is a lot more convenient in many ways than search results returned to an HTML page. In part 1 of this article I discussed Twitter search basics, and included a link to the Twitter search API, which I highly recommend you read if you want to do things like this.</li>
<li>Notice the encodeURIComponent function call. In this example, I pass  &#8220;crmForm.all.name.DataValue&#8221; into that function &#8212; this is the value of the &#8220;name&#8221; field on the Competitor form. If you were doing this for the Account or most other entities, it would be identical, but you might need to change the field name depending on what you want to do. EncodeURIComponent does things like replace spaces with the &#8220;%20&#8243; strings you see in URLs; it basically takes text strings and formats them properly as URLs, so get used to this function if you want to do things like this.</li>
<li>Also: notice the &#8220;&amp;tude=:)&#8221; and the other strings I tacked on to the end of the url. If I hadn&#8217;t commented out the alert, I&#8217;d see a URL like this just before the last line of this OnLoad event code gets run: <a href="http://search.twitter.com/search.atom?q=Kraft&amp;rpp=100&amp;lang=en&amp;tude">http://search.twitter.com/search.atom?q=Kraft&amp;rpp=100&amp;lang=en&amp;tude</a>=:) This search query looks for Kraft, then tells Twitter to return up to 100 results per page, then says to only look for English results, and finally says to look for &#8220;results with a positive attitude&#8221;. Obviously, if I&#8217;m a Kraft brand manager and I&#8217;m looking at search results for &#8220;Oreo Cakesters&#8221;, or &#8220;mac &#8216;n cheese&#8221;, I&#8217;d probably want to look at both &#8220;tude=:)&#8221; and &#8220;tude =:(&#8221; results, if you know what I mean!</li>
</ul>
<p>Refer back to Figure 2 for a second and notice the &#8220;Results mood&#8221; pulldown list. With very little additional effort (similar jscript to the above, only behind the Change event of the picklist attribute that gets selected) you can build in some flexibility along these lines.</p>
<h2>Extensions and the Importance of Twitter Search</h2>
<p>Here are some of the more obvious ways this could be extended. (You can probably think of a lot more &#8212; let me know if you have some good ones!)</p>
<ul>
<li>If I&#8217;m a Kraft brand manager, I&#8217;d want to use the Product entity, and add a bunch of my products (see above), and search on them with both <img src='http://www.dynamicscrmtrickbag.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  and <img src='http://www.dynamicscrmtrickbag.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  tude qualifiers, and maybe stack up how I&#8217;m doing against my competition.</li>
<li>If I really did want to keep track of my competitors, the Competitor entity would work well, but you might want to do this for their products as opposed to just the company name.</li>
<li>I think where it really starts to get cool is to store the results and start doing some analysis over time on the search results. You could store off these RSS data, say to a database, and really start to crunch some interesting numbers. For example, suppose you&#8217;re launching a new ad campaign for an existing product, and you want to see how it impacts the buzz about your product over time. Or suppose you&#8217;re watching to see how your competitors&#8217; campaigns are doing over time. Or suppose you&#8217;re managing a product recall or something along those lines and how that impacts discussion of your product over time&#8230;</li>
</ul>
<p>I could go on and on, but you probably get the point by now (if you&#8217;ve read this far! in which case, thank you very much). People who dismiss Twitter as a narcissistic time-suck are missing the point. If you&#8217;ve got 6 million+ people out there tweeting away about almost any topic you can think of, the chances are good they&#8217;re talking about things that matter to you. And if you can aggregate up all those tweets, you can actually learn some interesting things you might not already know.</p>
<p>The Truth is Out There&#8230;in the form of millions and millions of 140 character tweets.    </p>
<p>Cheers &#8211;</p>
<p>Richard</p>
<p><a href="mailto:richardk@imginc.com">richardk@imginc.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dynamicscrmtrickbag.com/2009/03/16/crm-twitter-mashup2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making Mashups with Dynamics CRM</title>
		<link>http://www.dynamicscrmtrickbag.com/2009/02/01/making-mashups-with-dynamics-crm/</link>
		<comments>http://www.dynamicscrmtrickbag.com/2009/02/01/making-mashups-with-dynamics-crm/#comments</comments>
		<pubDate>Sun, 01 Feb 2009 23:32:37 +0000</pubDate>
		<dc:creator>Richard Knudson</dc:creator>
				<category><![CDATA[Integration and SharePoint]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://www.dynamicscrmtrickbag.com/?p=33</guid>
		<description><![CDATA[Of Wikipedia’s five definitions of the term “mashup”, my favorite is for what they refer to as a web application hybrid: “a web application that combines data and/or functionality from more than one source”. Here’s the link: http://en.wikipedia.org/wiki/Mashup_(web_application_hybrid).
Dynamics CRM, with its relational database platform and easy customization features, is pretty good for mashups…if what you [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="margin: 0in 0in 10pt;">Of Wikipedia’s five definitions of the term “mashup”, my favorite is for what they refer to as a web application hybrid: “a web application that combines data and/or functionality from more than one source”. Here’s the link: <a href="http://en.wikipedia.org/wiki/Mashup_(web_application_hybrid)">http://en.wikipedia.org/wiki/Mashup_(web_application_hybrid)</a>.</p>
<p style="margin: 0in 0in 10pt;">Dynamics CRM, with its relational database platform and easy customization features, is pretty good for mashups…if what you want to mash up are data stored within Dynamics CRM. In an earlier blog post I discussed how you can integrate Dynamics CRM with SharePoint. There are lots of ways of doing that, but the one I wrote about treated SharePoint content as meta-data associated with a CRM record, and I showed an example of constructing a MOSS search dynamically, and exposing the search results on a CRM Account record’s form using an IFRAME. In a different post I showed a different example of a “CRM mashup”, where you could display, again for a CRM Account record, all of the Linkedin profiles of people associated with that Account.</p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;">I wasn’t thinking of those as mashups at the time, but after reading the above definition, they fit the term pretty well! The possibilities are limitless, and since a wide class of them use the same basic CRM customization techniques, you can pound them out pretty quickly after a little practice.</p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;">Here’s another CRM mashup, having to do with a web site I’ve been using lately called <a href="http://www.compete.com/">www.Compete.com</a>. One of the things you can do on Compete.com is enter one or more domain names, and Compete will display a chart with various data about their site traffic. For example, here’s a comparison of live.com and google.com:</p>
<p style="margin: 0in 0in 10pt;"> </p>
<p style="margin: 0in 0in 10pt;"><img class="alignleft size-full wp-image-34" title="compete_gvl2" src="http://www.dynamicscrmtrickbag.com/wp-content/uploads/2009/03/compete_gvl2.jpg" alt="compete_gvl2" width="322" height="280" /> </p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;">(It might be hard to tell from the picture, but Live closed the gap a little bit in January, according to these numbers.) You can do this for up to 5 domains at a time, and this is in the free version. They have a professional version you pay for that does more stuff; I haven’t taken the plunge with that one yet.</p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;">From the mashup standpoint, the most interesting thing about this is the URL: <a href="http://siteanalytics.compete.com/google.com+live.com/?metric=uv">http://siteanalytics.compete.com/google.com+live.com/?metric=uv</a></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;">Since you can access the free version of Compete anonymously, as long as you can construct a URL like this, you can display views like this in any web application where you can expose a page. In SharePoint you can use the Page Viewer Web Part to do it, in Dynamics CRM it’s going to be an IFRAME.</p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;">At the same time I was figuring this out I was doing a little research into different CRM blogs and web sites. I was interested in comparing some of the top sites, and seeing things like how much traffic they got, which if any were ad supported, and things like that. So of course, as any self-respecting CRM customizer would do, I whipped up a little custom entity in my CRM Online organization, called it CRMBlogsandSites, and added some custom attributes for the data I wanted to track. Here’s a view of the data grid:</p>
<p style="margin: 0in 0in 10pt;"> </p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: center"><span style="font-size: small; font-family: Calibri;"><img class="size-full wp-image-35   aligncenter" title="crmblogsandsites" src="http://www.dynamicscrmtrickbag.com/wp-content/uploads/2009/03/crmblogsandsites.jpg" alt="crmblogsandsites" width="370" height="246" /></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;">Since I’ve got the URL, I can do my mashup pretty easily. Here’s what one of the forms looks like – I’ll pick on Sonoma Partners in my example:</p>
<p style="margin: 0in 0in 10pt;"> </p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;">Notice that I’ve got attributes both for the URL and for the “traffic URL”. I created custom tabs on the form to display the web site, and the traffic chart from compete.com. The Site Traffic tab has an IFRAME on it I called “sitetraffic”. (CRM puts a prefix in front of the name, so in my code I’ll refer to it as “img_sitetraffic”. When a user’s on the form and clicks on the tab, it looks like this:</p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span style="font-size: small; font-family: Calibri;"><img class="size-full wp-image-36 alignnone" title="sonomatraffic" src="http://www.dynamicscrmtrickbag.com/wp-content/uploads/2009/03/sonomatraffic.jpg" alt="sonomatraffic" width="466" height="329" /></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;">To create this little mashup, here’s what I did:</p>
<p style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in;">1.       Created the custom entity I needed, crmblogsandsites, display name “CRM Blogs and Sites”.</p>
<p style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in;">2.       Added a custom attribute, img_trafficurl (“img” being the customization prefix, so that will most likely be different in your organization, although feel free to use img if you like), display name “Traffic URL”, type nvarchar, length 250, format URL.</p>
<p style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in;">3.       Opened up the entity’s form in customization mode and added a tab, called it Site Traffic, then added a section to the tab with the same name, but don’t display it. Also, you have to add the trafficurl attribute as a field on the form, don’t forget that!</p>
<p style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in;">4.       On that section, added an IFRAME. I called it “sitetraffic”, and CRM puts the text IFRAME in front of it, so in code you’ll refer to it as IFRAME_sitetraffic. Notice in the following picture that I’ve unchecked “Restrict cross-frame scripting”. Experiment with it both ways and I believe you’ll find it needs to be unchecked. Also notice the default url I’ve entered. As you’ll see this gets updated in code so it’s not critically important, but using this approach always reminds me of what it’s for, so I’ll often use it.</p>
<p style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in;"> </p>
<p style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; TEXT-ALIGN: center"><img class="size-full wp-image-39 aligncenter" title="iframeproperties1" src="http://www.dynamicscrmtrickbag.com/wp-content/uploads/2009/03/iframeproperties1.jpg" alt="iframeproperties1" width="333" height="384" /> </p>
<p style="margin: 0in 0in 0pt 0.5in;"> </p>
<p style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in;">5.       Added this little jscript snippet to the change event of the trafficurl field (remember that one from above?). Remember to check in the box that says “Event is enabled”, otherwise nothing will happen.</p>
<p style="margin: 0in 0in 0pt 0.5in;"> </p>
<p class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.5in;">crmForm.all.IFRAME_sitetraffic.src = crmForm.all.img_trafficurl.DataValue;</p>
<p style="margin: 0in 0in 0pt 0.5in;"> </p>
<p style="margin: 0in 0in 0pt 0.5in;"> </p>
<p style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in;">6.       Finally, navigate to the Form’s load event (click Form Properties, select OnLoad and click Edit), and add this code:</p>
<p style="margin: 0in 0in 0pt 0.5in;"> </p>
<pre class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.5in;">var CRM_FORM_TYPE_CREATE = 1;</pre>
<pre class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.5in;">var CRM_FORM_TYPE_UPDATE = 2;</pre>
<pre class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.5in;">var sitetrafficurl="";</pre>
<pre class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.5in;"><span style="font-family: Courier;">   switch (crmForm.FormType)</span></pre>
<pre class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.5in;"><span style="font-family: Courier;">   {</span></pre>
<pre class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.5in;"><span style="font-family: Courier;">      case CRM_FORM_TYPE_CREATE:</span></pre>
<pre class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.5in;">     </pre>
<pre class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.5in;"><span style="font-family: Courier;">         // don't need to do anything </span></pre>
<pre class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.5in;"><span style="font-family: Courier;">         break;</span></pre>
<pre style="margin: 0in 0in 0pt 0.5in;"> </pre>
<pre class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.5in;"><span style="font-family: Courier;">      case CRM_FORM_TYPE_UPDATE:</span></pre>
<pre class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.5in;"><span style="font-family: Courier;">        if (crmForm.all.img_trafficurl.DataValue != null)</span></pre>
<pre class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.5in;"><span style="font-family: Courier;">          { </span></pre>
<pre class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.5in;"><span style="font-family: Courier;">         // if it's filled in, put value of img_trafficurl field into sitetrafficurl variable</span></pre>
<pre class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.5in;"><span style="font-family: Courier;">         sitetrafficurl = crmForm.all.img_trafficurl.DataValue;</span></pre>
<pre class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.5in;"><span style="font-family: Courier;">           }</span></pre>
<pre class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.5in;"><span style="font-family: Courier;">         break;</span></pre>
<pre class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.5in;"><span style="font-family: Courier;">   }</span></pre>
<pre class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.5in;">// Set the IFRAME's URL</pre>
<pre class="MsoListParagraphCxSpLast" style="margin: 0in 0in 10pt 0.5in;">crmForm.all.IFRAME_sitetraffic.src = sitetrafficurl;</pre>
<p style="margin: 0in 0in 10pt;"> </p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;">Make sure the Event is Enabled checkbox is checked, save all your changes and publish your entity and see if it works. This fundamental technique comes up in lots of different contexts, so it might look familiar. The key is to figure out what kind of interesting information is out there on the web, related to an entity you have or can create in Dynamics CRM; then all you need to do is figure out how to construct the URL. And just remember: for any entity you have in Dynamics CRM, there’s probably meta-data for it out there somewhere!</p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;">And if you’ve created any good CRM mashups or have an idea for one, let me know.</p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;">Cheers &#8212; Richard</p>
<p style="margin: 0in 0in 10pt;"> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.dynamicscrmtrickbag.com/2009/02/01/making-mashups-with-dynamics-crm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Search SharePoint for Stuff for a Dynamics CRM Record</title>
		<link>http://www.dynamicscrmtrickbag.com/2008/12/01/search-sharepoint-for-stuff-for-a-dynamics-crm-record/</link>
		<comments>http://www.dynamicscrmtrickbag.com/2008/12/01/search-sharepoint-for-stuff-for-a-dynamics-crm-record/#comments</comments>
		<pubDate>Tue, 02 Dec 2008 00:08:49 +0000</pubDate>
		<dc:creator>Richard Knudson</dc:creator>
				<category><![CDATA[Integration and SharePoint]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://www.dynamicscrmtrickbag.com/?p=66</guid>
		<description><![CDATA[


Question


I&#8217;ve heard you can search SharePoint from external applications. I want to search it from a Dynamics CRM account form, so I can see all of the documents stored in our MOSS site related to an Account record in CRM. Is this possible?


Answer


Excellent question. (Meaning, I think it&#8217;s interesting AND I can answer it.) Here&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<table style="height: 100%;" border="0" cellspacing="2" cellpadding="4" width="100%">
<tbody>
<tr>
<td style="font-weight: bold; font-size: 10pt; color: #000066; border-bottom: #999999 1px solid;">Question</td>
</tr>
<tr>
<td><span style="font-size: x-small;">I&#8217;ve heard you can search SharePoint from external applications. I want to search it from a Dynamics CRM account form, so I can see all of the documents stored in our MOSS site related to an Account record in CRM. Is this possible?</span></td>
</tr>
<tr>
<td style="font-weight: bold; color: #000066; border-bottom: #999999 1px solid;"><span style="font-size: x-small;">Answer</span></td>
</tr>
<tr>
<td><span style="font-size: x-small;">Excellent question. (Meaning, I think it&#8217;s interesting AND I can answer it.) Here&#8217;s what I did &#8212; you can of course modify this to meet your specific requirements. Probably most important is the url I&#8217;m searching in the example, which is our firm&#8217;s intranet site. If you&#8217;re searching a SharePoint site that you navigate to by typing &#8216;</span><a href="http://foo.acme.com/"><span style="font-size: x-small;">http://foo.acme.com</span></a><span style="font-size: x-small;">&#8216;, sub that in for the &#8216;</span><a href="http://wss.imginc.com/"><span style="font-size: x-small;">http://wss.imginc.com</span></a><span style="font-size: x-small;">&#8216; references you see below and this will work fine.  </span><span style="font-size: x-small;"> 1. Add a tab to the Account form. I called mine &#8216;MOSS Search&#8217;. Add a section to it, and onto that section add an IFRAME. I called mine &#8216;moss_search&#8217;, so the full name of the IFRAME is IFRAME_moss_search.</span><span style="font-size: x-small;">2. Add the following code to the onLoad event of the Account form:</span></p>
<p><span style="font-size: x-small;">// JScript source code<br />
var CRM_FORM_TYPE_CREATE = 1;<br />
var CRM_FORM_TYPE_UPDATE = 2;</span></p>
<p><span style="font-size: x-small;">var sLiveSearchURL = &#8221;;</span></p>
<p><span style="font-size: x-small;">if(IsOnline())<br />
{<br />
 switch (crmForm.FormType)<br />
 {<br />
  case CRM_FORM_TYPE_CREATE:<br />
  <br />
   // Point to the IMG wss Intranet site when creating an account<br />
   imgSearchURL = &#8216;</span><a href="http://wss.imginc.com/"><span style="font-size: x-small;">http://wss.imginc.com</span></a><span style="font-size: x-small;">&#8216;;  <br />
   break;</span></p>
<p><span style="font-size: x-small;">  case CRM_FORM_TYPE_UPDATE:<br />
    <br />
   // Use MOSS search with this account&#8217;s name when updating account<br />
   imgSearchURL = &#8216;</span><a href="http://wss.imginc.com/search/pages/Results.aspx?k"><span style="font-size: x-small;">http://wss.imginc.com/search/pages/Results.aspx?k</span></a><span style="font-size: x-small;">=&#8217;;<br />
   <br />
   // Encode the account name and add it to the search string<br />
   imgSearchURL += encodeURIComponent(crmForm.all.name.DataValue);<br />
   <br />
   break;<br />
 }<br />
}</span></p>
<p><span style="font-size: x-small;">// Set the IFRAME&#8217;s URL<br />
crmForm.all.IFRAME_moss_search.src = imgSearchURL;</span></p>
<p> </p>
<p><span style="font-size: x-small;">One more point about the code snippet above: the imgSearchURL variable will need to be replaced by whatever the url is for your SharePoint search results page. Just do a search with no parameters to see what it is and sub that in.</span></p>
<p><span style="font-size: x-small;">This is a nice illustration of how you can integrate Dynamics CRM and SharePoint, but it also applies to other scenarios when you want to do what I call contextual searching from within Dynamics CRM. Let me know what you think!</span></td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.dynamicscrmtrickbag.com/2008/12/01/search-sharepoint-for-stuff-for-a-dynamics-crm-record/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

