<?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>Boyan Penev on Microsoft BI &#187; javascript</title>
	<atom:link href="http://www.bp-msbi.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bp-msbi.com</link>
	<description>A practical blog about Microsoft BI tools, techniques and practices written by a developer for other fellow developers.</description>
	<lastBuildDate>Sun, 29 Jan 2012 03:23:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Advanced javascript in Reporting Services</title>
		<link>http://www.bp-msbi.com/2008/09/advanced-javascript-in-reporting/</link>
		<comments>http://www.bp-msbi.com/2008/09/advanced-javascript-in-reporting/#comments</comments>
		<pubDate>Sat, 27 Sep 2008 03:38:00 +0000</pubDate>
		<dc:creator>Boyan Penev</dc:creator>
				<category><![CDATA[SSRS]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Reporting Services]]></category>

		<guid isPermaLink="false">http://www.bp-msbi.com/2008/09/advanced-javascript-in-reporting-services/</guid>
		<description><![CDATA[Often our requirements demand from us to use javascript in reporting services to navigate between reports. There are various reasons for using javascript, among others: Pop-ups &#8211; when we need to spawn another window for simultaneous viewing of lower level reports, or for displaying a full list of items (such as lists), which could be [...]]]></description>
			<content:encoded><![CDATA[<p>Often our requirements demand from us to use javascript in reporting services to navigate between reports. There are various reasons for using javascript, among others:</p>
<div>
<ul>
<li>Pop-ups &#8211; when we need to spawn another window for simultaneous viewing of lower level reports, or for displaying a full list of items (such as lists), which could be limited on our main report</li>
<li>Navigating from a <span id="SPELLING_ERROR_0" class="blsp-spelling-error">PerformancePoint</span> dashboard Reporting Services report to a purely Reporting services report and escaping from the <span id="SPELLING_ERROR_1" class="blsp-spelling-error">PerformancePoint</span> layer</li>
<li>Opening an custom html page (with or without passing parameters to it), which can then provide some additional functionality to our report (e.g. comments, editing fields&#8230;)</li>
<li>Providing a printable pop-up version of our report</li>
</ul>
<p>To achieve this functionality we need to use the Navigate to URL option in our report Navigation properties and we need to provide a javascript link to our target report.</p>
</div>
<div>Through using javascript we can pass parameters to the targeted URL and we can also choose how to display the targeted page. In example, to open a simple html page the javascript code we need to use in our Navigate to URL expression is:</div>
<div> </div>
<div><span class="Apple-style-span" style="font-family: 'courier new';"><span class="Apple-style-span" style="font-size: small;">=&#8221;javascript:void(window.open(&#8216;http://myserver/mypath/myasppage.html&#8217;, &#8216;_blank&#8217;))&#8221;</span></span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new';"><span class="Apple-style-span" style="font-size: small;"> </span></span></div>
<div>In this simple example we provide the javascript expression as a simple string without passing any report parameters or fields as page parameters. The result of clicking on our report link will be opening a new pop-up window, which will then display the html page at the specified address.</div>
<div> </div>
<div>First, lets explore the target javascript parameter. _blank means that every time we click on the link, we will spawn a new pop-up window. If we supply _parent as a value for the target parameter, javascript will pass the URL to the current window and will render the html page in the already open browser window, thus allowing us to replace the content of the current tab/window with new content. Another option is to provide a custom javascript property:</div>
<div> </div>
<div><span class="Apple-style-span" style="font-family: 'courier new';">=&#8221;javascript:void(window.open(&#8216;http://myserver/mypath/myasppage.html&#8217;, <span class="Apple-style-span" style="color: #663300;">&#8216;</span></span><span id="SPELLING_ERROR_2" class="blsp-spelling-error"><span class="Apple-style-span" style="font-family: 'courier new';"><span class="Apple-style-span" style="color: #663300;">subreport</span></span></span><span class="Apple-style-span" style="font-family: 'courier new';"><span class="Apple-style-span" style="color: #663300;">&#8216;</span>))&#8221;</span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new';"> </span></div>
<div>which will result in opening a pop-up which we can reuse afterwards from any javascript link. If we have more than one javascript link on our report and we want to open some or all of those in the same pop-up window, we can name our target windows and then use the name in multiple javascript links, which then render their target pages in the same pop-up.</div>
<div>Furthermore, we can specify other javascript properties. An example of using some of these is:</div>
<div> </div>
<div><span class="Apple-style-span"><span class="Apple-style-span"><span class="Apple-style-span" style="font-family: 'courier new';"><span class="Apple-style-span" style="font-size: small;">=&#8221;javascript:void(window.open(&#8216;http://myserver/mypath/myasppage.html&#8217;,</span></span><span class="Apple-style-span" style="font-family: 'courier new';"><span class="Apple-style-span" style="font-size: small;"> </span></span></span><span class="Apple-style-span"><span class="Apple-style-span"><span class="Apple-style-span" style="font-family: 'courier new';"><span class="Apple-style-span" style="font-size: small;">&#8216;_blank&#8217;, </span><span class="Apple-style-span" style="color: #663333;"><span class="Apple-style-span" style="font-size: small;">&#8216;</span></span></span></span></span><span style="font-size: 0;"><span class="Apple-style-span"><span class="Apple-style-span" style="font-family: 'courier new';"><span class="Apple-style-span" style="color: #663333;"><span class="Apple-style-span" style="font-size: small;">width=300,height=300,top=300,left=500,toolbar=1,</span></span></span><span id="SPELLING_ERROR_3" class="blsp-spelling-error"><span class="Apple-style-span" style="font-family: 'courier new';"><span class="Apple-style-span" style="color: #663333;"><span class="Apple-style-span" style="font-size: small;">menubar</span></span></span></span><span class="Apple-style-span" style="font-family: 'courier new';"><span class="Apple-style-span" style="color: #663333;"><span class="Apple-style-span" style="font-size: small;">=1,location=1,status=1,</span></span></span><span id="SPELLING_ERROR_4" class="blsp-spelling-error"><span class="Apple-style-span" style="font-family: 'courier new';"><span class="Apple-style-span" style="color: #663333;"><span class="Apple-style-span" style="font-size: small;">scrollbars</span></span></span></span><span class="Apple-style-span" style="font-family: 'courier new';"><span class="Apple-style-span" style="color: #663333;"><span class="Apple-style-span" style="font-size: small;">=1,</span></span></span><span id="SPELLING_ERROR_5" class="blsp-spelling-error"><span class="Apple-style-span" style="font-family: 'courier new';"><span class="Apple-style-span" style="color: #663333;"><span class="Apple-style-span" style="font-size: small;">resizable</span></span></span></span><span class="Apple-style-span" style="font-family: 'courier new';"><span class="Apple-style-span" style="color: #663333;"><span class="Apple-style-span" style="font-size: small;">=1&#8242;</span></span><span class="Apple-style-span" style="font-size: small;">))&#8221;</span></span></span></span></span></div>
<div><span class="Apple-style-span"><span style="font-size: 0;"><span class="Apple-style-span"><span class="Apple-style-span" style="font-family: 'courier new';"><span class="Apple-style-span" style="font-size: small;"> </span></span></span></span></span></div>
<div>For us as Reporting Services developers the more important ones are the width, height, toolbar, <span id="SPELLING_ERROR_6" class="blsp-spelling-error">menubar</span> and <span id="SPELLING_ERROR_7" class="blsp-spelling-error">resizable</span> (not <span id="SPELLING_ERROR_8" class="blsp-spelling-error">resizeable</span>). The toolbar and <span id="SPELLING_ERROR_9" class="blsp-spelling-error">menubar</span> have slightly different meanings in different browsers. In IE 6 and IE 7 enabling and disabling (setting them to 0 or 1) these result in different browser elements to get displayed, so testing them should be done in all the browsers our users could use. The <span id="SPELLING_ERROR_10" class="blsp-spelling-error">resizable</span> property allows/disallows resizing (including maximising) the pop-up window.</div>
<div> </div>
<div>To form the URL we can either point to Report Manager or to the Report Server directly. Pointing to Report Manager will display the report with the report manager wrapper, which is in most cases not required. Supplying the Report Server URL results in rendering only the actual report in the javascript window. To form the <span id="SPELLING_ERROR_11" class="blsp-spelling-error">ReportServer</span> URL we need to supply the full path to it and the report. An example of a complete URL is:</div>
<div> </div>
<div><span class="Apple-style-span" style="font-family: 'courier new';">http://myserver/ReportServer?/myfolder/myreport</span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new';"> </span></div>
<div>or as a part of a javascript pop-up expression in Reporting Services:</div>
<div> </div>
<div><span class="Apple-style-span" style="font-family: 'courier new';">=&#8221;javascript:void(window.open(<span class="Apple-style-span" style="color: #663333;">&#8216;http://myserver/ReportServer?/myfolder/myreport&#8217;</span>,&#8217;_</span><span class="Apple-style-span" style="font-family: 'courier new';">blank&#8217;))&#8221;</span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new';"> </span></div>
<div>It is always a good idea to parametrise the URL and to supply the server and the path as a Reporting Services field or parameter to the expression:</div>
<div> </div>
<div><span class="Apple-style-span" style="font-family: 'courier new';">=&#8221;javascript:void(window.open(<span class="Apple-style-span" style="color: #663333;">&#8216;&#8221; &amp; Parameters!</span></span><span id="SPELLING_ERROR_12" class="blsp-spelling-error"><span class="Apple-style-span" style="font-family: 'courier new';"><span class="Apple-style-span" style="color: #663333;">ServerAddress</span></span></span><span class="Apple-style-span" style="font-family: 'courier new';"><span class="Apple-style-span" style="color: #663333;">.Value &amp; &#8220;?&#8221; &amp; Parameters!</span></span><span id="SPELLING_ERROR_13" class="blsp-spelling-error"><span class="Apple-style-span" style="font-family: 'courier new';"><span class="Apple-style-span" style="color: #663333;">ReportPath</span></span></span><span class="Apple-style-span" style="font-family: 'courier new';"><span class="Apple-style-span" style="color: #663333;">.Value &amp; &#8220;</span></span><span id="SPELLING_ERROR_14" class="blsp-spelling-error"><span class="Apple-style-span" style="font-family: 'courier new';"><span class="Apple-style-span" style="color: #663333;">myreport</span></span></span><span class="Apple-style-span" style="font-family: 'courier new';"><span class="Apple-style-span" style="color: #663333;">&#8216;</span>,&#8217;_blank&#8217;))&#8221;</span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new';"> </span></div>
<div>which allows us to maintain the report in our relational back-end easing the deployment of our solution to different environment without changing all our reports.</div>
<div> </div>
<div>We can also specify Report Server commands in the URL:</div>
<div> </div>
<div><span class="Apple-style-span" style="font-family: 'courier new';">=&#8221;javascript:void(window.open(&#8216;&#8221; &amp; Parameters!</span><span id="SPELLING_ERROR_15" class="blsp-spelling-error"><span class="Apple-style-span" style="font-family: 'courier new';">ServerAddress</span></span><span class="Apple-style-span" style="font-family: 'courier new';">.Value &amp; &#8220;?&#8221; &amp; Parameters!</span><span id="SPELLING_ERROR_16" class="blsp-spelling-error"><span class="Apple-style-span" style="font-family: 'courier new';">ReportPath</span></span><span class="Apple-style-span" style="font-family: 'courier new';">.Value &amp; &#8220;</span><span id="SPELLING_ERROR_17" class="blsp-spelling-error"><span class="Apple-style-span" style="font-family: 'courier new';">myreport&amp;</span></span><span class="Apple-style-span" style="font-family: 'courier new';"><span class="Apple-style-span" style="color: #663333;">rs:Command=render&amp;</span></span><span id="SPELLING_ERROR_18" class="blsp-spelling-error"><span class="Apple-style-span" style="font-family: 'courier new';"><span class="Apple-style-span" style="color: #663333;">rc</span></span></span><span class="Apple-style-span" style="font-family: 'courier new';"><span class="Apple-style-span" style="color: #663333;">:Parameters=true</span>&#8216;,&#8217;_blank&#8217;))&#8221;</span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new';"> </span></div>
<div> </div>
<div>These two commands make Report Server render the report without evaluating the item first (improving performance), and also show the report parameters to the user. There is a thorough article on <span id="SPELLING_ERROR_19" class="blsp-spelling-error">MSDN</span> showing the various commands that can be passed to the <span id="SPELLING_ERROR_20" class="blsp-spelling-error">reportserver</span> and I will not go any further in explaining these in this post.</div>
<div> </div>
<div>We can also pass report parameters to our target reports:</div>
<div> </div>
<div><span class="Apple-style-span" style="font-family: 'courier new';">=&#8221;javascript:void(window.open(&#8216;&#8221; &amp; Parameters!</span><span id="SPELLING_ERROR_21" class="blsp-spelling-error"><span class="Apple-style-span" style="font-family: 'courier new';">ServerAddress</span></span><span class="Apple-style-span" style="font-family: 'courier new';">.Value &amp; &#8220;?&#8221; &amp; Parameters!</span><span id="SPELLING_ERROR_22" class="blsp-spelling-error"><span class="Apple-style-span" style="font-family: 'courier new';">ReportPath</span></span><span class="Apple-style-span" style="font-family: 'courier new';">.Value &amp; &#8220;</span><span id="SPELLING_ERROR_23" class="blsp-spelling-error"><span class="Apple-style-span" style="font-family: 'courier new';">myreport&amp;</span></span><span class="Apple-style-span" style="font-family: 'courier new';">rs:Command=render&amp;</span><span id="SPELLING_ERROR_24" class="blsp-spelling-error"><span class="Apple-style-span" style="font-family: 'courier new';">rc</span></span><span class="Apple-style-span" style="font-family: 'courier new';">:Parameters=true&amp;<span class="Apple-style-span" style="color: #663333;">Period=&#8221; &amp; Parameters!Period.Value &amp; &#8220;</span>&#8216;,&#8217;_blank&#8217;))&#8221;</span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new';">  </span></div>
<div>This expression will then pass our Period parameter to the <span id="SPELLING_ERROR_25" class="blsp-spelling-error">subreport</span> through the URL. We can specify multiple parameters like this:</div>
<div> </div>
<div><span class="Apple-style-span" style="font-family: 'courier new';">=&#8221;javascript:void(window.open(&#8216;&#8221; &amp; Parameters!</span><span id="SPELLING_ERROR_26" class="blsp-spelling-error"><span class="Apple-style-span" style="font-family: 'courier new';">ServerAddress</span></span><span class="Apple-style-span" style="font-family: 'courier new';">.Value &amp; &#8220;?&#8221; &amp; Parameters!</span><span id="SPELLING_ERROR_27" class="blsp-spelling-error"><span class="Apple-style-span" style="font-family: 'courier new';">ReportPath</span></span><span class="Apple-style-span" style="font-family: 'courier new';">.Value &amp; &#8220;</span><span id="SPELLING_ERROR_28" class="blsp-spelling-error"><span class="Apple-style-span" style="font-family: 'courier new';">myreport&amp;</span></span><span class="Apple-style-span" style="font-family: 'courier new';">rs:Command=render&amp;</span><span id="SPELLING_ERROR_29" class="blsp-spelling-error"><span class="Apple-style-span" style="font-family: 'courier new';">rc</span></span><span class="Apple-style-span" style="font-family: 'courier new';">:Parameters=true&amp;<span class="Apple-style-span" style="color: #663333;">Period=&#8221; &amp; Parameters!Period.Value &amp; &#8220;&amp;Business_Unit=&#8221; &amp; Parameters!Business_Unit.Value &amp; &#8220;</span>&#8216;,&#8217;_blank&#8217;))&#8221;</span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new';"> </span></div>
<div>concatenating them with the &amp; character. Please note that there is a 255 character restriction on the length of the URL, so multi-value parameters can be problematic to pass if the set of values is too large.</div>
<div>Another point to note here is that we should not pass the <span id="SPELLING_ERROR_30" class="blsp-spelling-error">UserId</span> of our users as a parameter. Instead of doing this we should always capture the <span id="SPELLING_ERROR_31" class="blsp-spelling-error">UserId</span> of the person viewing the report with User!<span id="SPELLING_ERROR_32" class="blsp-spelling-error">UserID</span>.Value in each report, which minimises the security risk of someone gaining access to sensitive report data through passing an edited URL to the browser with someone <span id="SPELLING_ERROR_33" class="blsp-spelling-error">else&#8217;s</span> user id in the parameters section.</div>
<div>As a last section I would like to address the problem with passing a <span id="SPELLING_ERROR_34" class="blsp-spelling-error">MDX</span> expression as a parameter value. In case we have an <span id="SPELLING_ERROR_35" class="blsp-spelling-error">MDX</span> value such as:</div>
<div> </div>
<div><span class="Apple-style-span" style="font-family: 'courier new';">[Business Unit].[Business Unit Name].<span class="Apple-style-span" style="color: #ff0000;">&amp;</span>[Australia]</span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new';"> </span></div>
<div>the &amp; character will be interpreted as a concatenation between parameters and the URL will be parsed with this presumption. To avoid this we can use the escape() function in javascript to substitute the ampersand character with its URI value of %26:</div>
<div> </div>
<div><span class="Apple-style-span" style="font-family: 'courier new';">=&#8221;javascript:void(window.open(&#8216;&#8221; &amp; Parameters!</span><span id="SPELLING_ERROR_36" class="blsp-spelling-error"><span class="Apple-style-span" style="font-family: 'courier new';">ServerAddress</span></span><span class="Apple-style-span" style="font-family: 'courier new';">.Value &amp; &#8220;?&#8221; &amp; Parameters!</span><span id="SPELLING_ERROR_37" class="blsp-spelling-error"><span class="Apple-style-span" style="font-family: 'courier new';">ReportPath</span></span><span class="Apple-style-span" style="font-family: 'courier new';">.Value &amp; &#8220;</span><span id="SPELLING_ERROR_38" class="blsp-spelling-error"><span class="Apple-style-span" style="font-family: 'courier new';">myreport&amp;</span></span><span class="Apple-style-span" style="font-family: 'courier new';">rs:Command=render&amp;</span><span id="SPELLING_ERROR_39" class="blsp-spelling-error"><span class="Apple-style-span" style="font-family: 'courier new';">rc</span></span><span class="Apple-style-span" style="font-family: 'courier new';">:Parameters=true&amp;Period=&#8221; &amp; Parameters!Period.Value &amp; &#8220;&amp;Business_Unit=&#8217; <span class="Apple-style-span" style="color: #663333;">+ escape(&#8216;&#8221; &amp; Parameters!Business_Unit.Value &amp; &#8220;&#8216;)</span>,&#8217;_blank&#8217;))&#8221;</span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new';"> </span></div>
<div>This way we can pass any <span id="SPELLING_ERROR_40" class="blsp-spelling-error">MDX</span> or any other special or reserved character through the URL.</div>
<div>In conclusion, javascript in Reporting Services widens our set of tools to tackle difficult requirements in a relatively simple way. The combination of the powerful javascript language and its widespread support and the options that Reporting Services provides for report rendering control through the URL is very powerful and report developers can benefit through exploring both areas.</div>
]]></content:encoded>
			<wfw:commentRss>http://www.bp-msbi.com/2008/09/advanced-javascript-in-reporting/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
	</channel>
</rss>

