{"id":73,"date":"2010-12-04T11:44:00","date_gmt":"2010-12-04T11:44:00","guid":{"rendered":"\/lisa\/post\/2010\/12\/04\/Everything-has-a-point-Part-Un.aspx"},"modified":"2010-12-04T11:44:00","modified_gmt":"2010-12-04T11:44:00","slug":"everything-has-a-point-part-un","status":"publish","type":"post","link":"https:\/\/spacefold.com\/lisa\/2010\/12\/04\/everything-has-a-point-part-un\/","title":{"rendered":"Everything has a point, Part Un"},"content":{"rendered":"<h2>&nbsp;<\/h2>\n<p>Today&#8217;s title comes from Harry Nilsson, who once, quite sensibly, <a title=\"wikipedia on Nilsson- The Point\" href=\"http:\/\/en.wikipedia.org\/wiki\/The_Point!\" target=\"_blank\" rel=\"noopener\">wrote<\/a><\/p>\n<blockquote>\n<h4 style=\"PADDING-LEFT: 30px\">\n<p>A point in every direction is&nbsp;the same as no point at all.<\/p>\n<\/h4>\n<\/blockquote>\n<p>That&#8217;s sometimes how I feel about various SSRS features.&nbsp; They get introduced, they look groovy&#8230; hey! You could do anything with this!&nbsp;<\/p>\n<p>Then after a closer look you find there isn&#8217;t anything you really want to do with them.<\/p>\n<h2>Variable cloudiness<\/h2>\n<p>A couple of months ago, I wrote a <a title=\"blog post discussing group variables\" href=\"\/lisa\/2010\/08\/02\/YAPS-on-Why-Groups-dont-make-everything-childs-play-in-RDLs\/\">Just-So Formatting story<\/a>&nbsp;about why group variables just didn&#8217;t cut it for&nbsp;Ramdas&#8217; requirement.&nbsp;<\/p>\n<p>I said I couldn&#8217;t find a real reason to use group variables, so far.&nbsp;I also said that I wasn&#8217;t sure of the solution I provided in other versions of SSRS than I was testing.&nbsp;<\/p>\n<p>&nbsp;In both statements, regarding group variables as well as my solution-not-using-group-variables,&nbsp;my critical area of concern is the <strong>sequence of<\/strong> <strong>events.&nbsp;<\/strong> This sequence includes&nbsp;evaluation of variables and other types of actions such as triggering expressions and custom code, during the run of a report.&nbsp; Figuring out the order in which everything happens is critical to, well, getting it to happen.<\/p>\n<p>Anyway&#8230; &nbsp;last week I came upon a just-so formatting requirement of my own, that could not have been resolved without group variables!&nbsp; Wow!<\/p>\n<p>In the interests of equal time, and since this was completely new to me and might be to you, I thought I&#8217;d tell you about it.<\/p>\n<p class=\"NB\">There may be a way to delay or change evaluation of variables in SSRS with their scope, as there is in SSIS&nbsp; &#8212; but this just gives you more permutations to test.&nbsp; It doesn&#8217;t resolve anything.&nbsp; <\/p>\n<p>FWIW the &#8220;DeferVariableEvaluation&#8221; option that is new in 2008 R2 appears to variables on the Report scope, and doesn&#8217;t really do much for the problem at hand.&nbsp; <\/p>\n<p>Scoped variables, such as the group-level variable I&#8217;m going to use here, are evaluated once per group.&nbsp; The significance question is: <strong>when<\/strong> <strong>within the sequenc<\/strong>e of the other things the group&nbsp;evaluates and processes?&nbsp;<\/p>\n<p>Even if the documentation was clearer about this &#8212; and it&#8217;s unusually spartan &#8212; you would still have to test, test, test, using the context of your own code to find out the truth.<\/p>\n<h3>Our &#8220;simple&#8221; requirement<\/h3>\n<p>&nbsp;A report has a list control that groups on students.&nbsp; Within each student, we wish to display a head shot identifying the student or, if none is available, a stock image.<\/p>\n<p>The image&#8217;s value expression calls a function. While&nbsp;that fact is not strictly relevant, the expression&nbsp;looks something like this:<\/p>\n<p class=\"code\">=Code.GetStudentPicture( <br \/>&nbsp;&nbsp; Parameters!ImageFileSkeleton.Value, <strong>Fields!StudentID.Value<\/strong>)<\/p>\n<p>&nbsp;&nbsp;&#8230; and the function in question looks something like this:<\/p>\n<p class=\"code\"><span style=\"color: #0000ff; \">Function<\/span>&nbsp;GetStudentPicture(tFileSkel <span style=\"color: #0000ff; \">As String<\/span>, tStudentID <span style=\"color: #0000ff; \">As String<\/span> ) <span style=\"color: #0000ff; \">As String<br \/>&nbsp;&nbsp;<br \/>&nbsp;&nbsp;Dim<\/span>&nbsp; testFile <span style=\"color: #0000ff; \">As String = String<\/span>.Format(tFileSkel, tStudentID.Trim())<br \/>&nbsp;&nbsp;<span style=\"color:#0000ff\">If<\/span>&nbsp; System.IO.File.Exists(testFile) <span style=\"color: #0000ff; \">Then&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Return<\/span> <span style=\"color: #a31515; \">&#8220;file:\/\/&#8221; <\/span>&amp; testFile&nbsp; <br \/>&nbsp;&nbsp; <span style=\"color: #0000ff; \">Else&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Return<\/span><span style=\"color: #a31515; \">&#8220;file:\/\/&#8221;<\/span> &amp; <span style=\"color: #0000ff; \">String<\/span>.Format(tFileSkel,<span style=\"color: #a31515; \">&#8220;DefaultStudent&#8221;<\/span>)&nbsp; <br \/>&nbsp;&nbsp; <span style=\"color: #0000ff; \">End&nbsp;If&nbsp; <\/p>\n<p>End&nbsp;Function<\/span><\/p>\n<p>How much more generic could the problem be?&nbsp; What could possibly go wrong here ?<\/p>\n<h3>Oh, wait.&nbsp; That&#8217;s right.<\/h3>\n<p>The images are stored in the file system; never mind where.&nbsp; Once I remembered to set up an Execution Account in SSRS, with appropriate rights to this folder (ugh), I figured my job here was done.<\/p>\n<p class=\"NB\">Well.. I&#8217;m simplifying a bit.&nbsp; Because of the <strong>File.Exists<\/strong> test, an Execution Account with appropriate rights isn&#8217;t really enough.&nbsp; You have to set code in RDLs to be trusted.&nbsp; However, that part of the requirement <strong>isn&#8217;t<\/strong> generic, and you probably wouldn&#8217;t even put your images in a shared folder.&nbsp; You&#8217;d put them in a database or access them through a URL.&nbsp; Right?<\/p>\n<p>Next,&nbsp;I added a subreport into the list control,&nbsp;to handle most of the information for the current student, and everything was still fine.&nbsp; The image and header information &#8220;sat&#8221; above this subreport, like a frame.<\/p>\n<p>Then I added another subreport, this time adjacent to the image.&nbsp; Uh-oh.<\/p>\n<p>Our pesky little friend&nbsp;Sequence O. Execution didn&#8217;t like that change.&nbsp; Suddenly my function wasn&#8217;t receiving any value at all for the Fields!StudentID.Value, which, as far as I knew, was perfectly in scope at the time.<\/p>\n<p>Please don&#8217;t ask me to explain this.&nbsp; (It took me tons of time even to understand why it was broken. I did check for any overlap, but there didn&#8217;t seem to be anything like that going on.)<\/p>\n<p>Moving the relative positions of the image and the subreport was not an option.<\/p>\n<h3>Group variable to the rescue!<\/h3>\n<p>Creating a group variable to store the value of Fields!StudentID.Value ensured that the string was in scope when I called my function.&nbsp; All I had to do was change the expression for the image to :<\/p>\n<p class=\"code\">=Code.GetStudentPicture( <br \/>&nbsp;&nbsp; Parameters!ImageFileSkeleton.Value, <strong>Variables!ThisStudent.Value<\/strong>)<\/p>\n<p>&nbsp;&#8230; and life was good.&nbsp;<\/p>\n<p>This annoyance wasn&#8217;t specific to the image control; it turned out that every dataset field I was evaluating within that specific block in the layout had the same problem.&nbsp; I just stored them all to variables on the &#8220;way in&#8221;, and substituted the variables for direct evaluation of the fields, in each case.<\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" src=\"\/lisa\/wp-non\/migrated\/2010\/12\/GroupVar.png\" alt=\"\" \/><\/p>\n<p style=\"text-align: left;\">And that&#8217;s how LSN found out the point of group variables.<\/p>\n<p style=\"text-align: left;\">I&#8217;m definitely filing this solution away for future reference, because it&#8217;s not the first time that subreports have snuck up and bit me like this.<\/p>\n<p style=\"text-align: left;\">Miracles don&#8217;t cease there.&nbsp; This week,&nbsp;I found out that even the completely irritating Word renderer in SSRS 2008 can sometimes have a point. In Part Deux of this little mini-series, I&#8217;ll tell you about that.<\/p>\n<h2 style=\"text-align: left;\">Cloudy with more than a chance of meatheads<\/h2>\n<p style=\"text-align: left;\">I have a small announcement to make regarding the status of this blog:<\/p>\n<p style=\"text-align: left;\"><strong>Comments are now totally closed<\/strong>.<\/p>\n<p style=\"text-align: left;\">The noise-to-signal ratio of the comments, and the ton of work it took to clean them up, finally got the better of me.&nbsp; Not to mention the unpleasant sticker shock when the spam traffic ate Spacefold.com out of house and bandwidth this month.<\/p>\n<p style=\"text-align: left;\">Please email me if you have questions or need help, I&#8217;m always happy to hear from <strong>you<\/strong>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Today&#8217;s title comes from Harry Nilsson, who once, quite sensibly, wrote A point in every direction is&nbsp;the same as no point at all. That&#8217;s sometimes how I feel about various SSRS features.&nbsp; They get introduced, they look groovy&#8230; hey! You could do anything with this!&nbsp; Then after a closer look you find there isn&#8217;t<a class=\"more-link\" href=\"https:\/\/spacefold.com\/lisa\/2010\/12\/04\/everything-has-a-point-part-un\/\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,6],"tags":[],"class_list":["post-73","post","type-post","status-publish","format-standard","hentry","category-reporting","category-sql-server"],"_links":{"self":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/posts\/73","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/comments?post=73"}],"version-history":[{"count":0,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/posts\/73\/revisions"}],"wp:attachment":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/media?parent=73"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/categories?post=73"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/tags?post=73"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}