SSRS - embed URL and formatting characters in parameter - reporting-services

I'm making a form letter in SSRS 2012 that will be delivered by email. I had it working fine but now the powers that be have requested a much more dynamic aspect to it based on the individual recipient... Different paragraphs now need to be included/excluded based on the target.
With that, I pulled the body of the email out of SSRS and am now assembling it in SQL Server and passing it over to SSRS as a parameter (so that I don't wind up making a dozen SSRS reports to handle the need).
I have that part working too now, but hit a snag... There were a few bullet points as well as URL's that could look nicer. I'd like to force an indention before the bullet points and replace www.mysite.com with something prettier like "Click Here". On the SSRS side of the fence, I currently just have a single text box (and ideally would keep it that way) which contains an expression that references my "EmailBody" parameter.
So far, I have not found the right combination of words to send to Google to see if this is possible, so I figured I'd go straight to the pros here. I did try formatting the output in a similar manner to what an expression would look like ( ="This is the body of my email" ) and it just passed that straight on through to the final output.
Any ideas would be appreciated!
Jason

In case it helps anyone else, I figured out the secret.
Change your text box in SSRS to expect HTML by right-clicking on the placeholder (<< EXP >>) inside the text box, selecting Placeholder Properties, and change the Markup Type to "HTML - Interpret HTML tags as styles".
After that, go back to the SQL Server side of the fence and change the text you are sending as a parameter to HTML with whatever styling properties you desire.

Sounds like you're on the right track with the HTML markup. I also wanted to suggest that you can use a data-driven subscription. Have the query generate the HTML you want. Then have that populate the body of the email. That way there's no need for any attachments. This has come in handy when I wanted to display a small table of data for viewing on a mobile device rather than having to open an Excel attachment.

Related

MS Access Expression used to link to an image

I have quite a simple issue that is baffling me.
I'm building a product database, simple enough, but I'm having issues with automatically pulling in the product images.
All images reside on a server with a standard naming convention. [SKU#]_Main.jpg, [SKU#]_AV.jpg, [SKU#]_AV1.jpg, etc.
They all reside in one of two folders: w:\Photos\02 Gear\High Res\ or W:\Photos\01 Apparel\High Res\
These paths are used to populate data sheets for upload to our online retailers.
Wanting to make product data entry for all these image paths automatic I created the following:
FilePath list box with the two path choices.
Textboxes: Main, AV, AV1 etc. that are automatically populated with this expression: =[FilePath] & [SKU] & "_AV.jpg" ( the "_AV" changing for each variant.
Then, image boxes look to the textboxes for the filepath and displays the image.
If the filepath is just typed into the Main, AV, etc fields the image box populates. If I use the expression it doesn't, even though the text in the Main, AV, etc fields are identical.
In the image the first 3 lines are typed in. The image boxes populate. The next lines have the expression. By all outward appearances the file path 'looks' the same. But it won't pull the image.
So what obvious piece am I missing? I know I'm going to feel like an idiot once one of you kind folk answer :)
You are probably fighting with the hyperlink syntax and may have to use HyperlinkPart:
CleanUrl = HyperlinkPart(SavedUrl, acAddress)
I wrote an article dealing with this (and more):
Show pictures directly from URLs in Access forms and reports
A working demo is for download at that page.

HTML Form: Can submitted GET/POST parameters be suppressed using only HTML or CSS?

I am volunteering on a website-based project that is trying to make all pages fully operable JavaScript free before adding any JavaScript for enhancements, and I was asked to investigate whether or not a particular scenario could be handled purely through HTML/CSS.
What we have is a form that is populated to help us filter a list of tickets that are displayed on the screen after a page update through a GET action, which itself works fine, but the concern with the current implementation is that the URL cannot be made into a permanent link. The request, however, to keep the permanent link as minimal as possible, is to only send GET parameters for fields that are populated with something (so, suppressing GET parameters for fields that are blank) instead of having a different GET parameter for each form field on the page.
I have thought of several ways that could be done, most including JavaScript (example: create fields with ids but no names and a hidden field w/ name that uses JS to grab the data from the fields), but also one that would be a POST action with a redirect back to the GET with a human readable string that could be permanently used. The lead dev, however would prefer not to go through the POST/redirect method if at all possible.
That being said, I'm trying to make sure I cover all my bases and ask experts their thoughts on this before I strongly push for the POST/redirect solution: Is there a way using only HTML & CSS to directly suppress GET parameters of a form for fields that are blank without using a POST/redirect?
No, suppressing fields from being submitted in an HTML form with method of "GET" is not possible without using JavaScript, or instead submitting the form with a POST method and using a server side function to minimize the form.
What fields are submitted are defined by the HTML specification and HTML and CSS alone cannot modify this behavior and still have the browser be compliant with the standards.
No, you cannot programmatically suppress any default browser behavior without using some kind of client scripting language, like JavaScript.
As a side note, you say "JavaScript for enhancements", but JavaScript is not used for enhancements these days. And no one in the real world would except a decent front-end without the use of JavaScript. I would suggest you simply use JavaScript.
I do not think you can avoid Javascript here to pre process before submission to eliminate unchanged /empty form fields.

Creating custom SSRS handler for field with HTML

I have an SSRS 2008 report with a field that contains and is configured to render as HTML. Some of the text in this field may contain IMG tags, and the IMG tag is not among the tags SSRS natively supports within its HTML rendering extension.
I am trying to find a way to write a custom handler to hook into the processing of this field that will let me look at the raw HTML before the SSRS handler processes it, in the hopes of grabbing IMG tags, extracting the SRC URL and getting the raw bytes of an image to insert on the fly in a way SSRS will accept, yet retaining the HTML SSRS will render.
From what I've read and seen so far, if a field is marked to render as HTML, the SSRS processor grabs it and parses it entirely before any handler could modify it, meaning the IMG tag is (would be) discarded before I could do anything with it (or even know it was present). The only option I see is to turn off the HTML rendering entirely, thus losing the benefit of the tags SSRS can recognize.
EDIT: Per Jamie's response below, I'm beginning to think the "2nd half" of this issue may prove harder than I realized: Is it even possible to programmatically add an Image to an SSRS Report at runtime (obviously through code/custom assembly)? That is, I'd like to write some code that might look something like this (pseudocode)
'Conceptual Pseudocode I'd like to be able to write
'for dynamic addition of Image element in SSRS report
'Is this even possible?? Is there a documented Report
'object model??
Public Function AddImage(imageBytes() as Byte) as Image
Dim newImage as New Image()
newImage.SetBytes(imageBytes)
Report.Add(newImage)
return newImage
End Function
I'm hoping I'm just overlooking something simple that prevents me from grabbing the raw, unprocessed HTML, and someone else might be able to point me in the right direction on how to grab it.
EDIT: I have created and implemented this solution within the SSRS development environment and it works. WOOHOO :) It did require some hoop-jumping with creating a Single-Threaded Apartment thread to host the WebBrowser control, and to create a message pump, but it does work! **
As I was literally typing up the message to a co-worker that this issue was a non-starter, I did have a bit of an inspiration on a way to solve this problem. I know this post hasn't generated a great deal of response, but just in case someone else finds themselves in a similar problem, I'm going to share what I've implemented in a "petri dish" scenario that, provided I get all the code permission issues resolved, should allow me a decent solution to this problem.
With SSRS inability to handle an IMG tag insurmountable, I actually thought of an idea that took the HTML rendering away from SSRS entirely. To do this, I created custom code that hands off the HTML rendering to a WebBrowser control, then copies the rendered result as an image. It does the following:
Instantiates a WebBrowser control of a given width and height.
Sets the DocumentText property of that control to the HTML from TinyMCE
Waits for the DocumentText to completely render.
Creates a bitmap equal to the size of the control.
Uses the undocumented and presumably unsupported DrawToBitmap method of the WebBrowser to draw the rendered HTML to a bitmap.
Copies the Bitmap to an Image
Saves the Image as a .png file
Returns the path to the .png as the result of the function.
In SSRS, I plan to replace the erstwhile HTML text field with an external Image control that will then call the above method and render the image file. I may alter that to simply draw the image to the SSRS Image control directly, but that's a final detail I'll resolve later. I think this basic design is going to work. Its a little kludgey, but I think it will work.
I have some permissions issues to work out with the code that SSRS will allow me to call at runtime, but I'm confident I'll get those sorted out (even if I end up moving the code to a separate assembly). Once this is tested and working, I plan to mark this as the answer.
Thanks to those who offered suggestions.
I've done something similar with success: We had an HTML "Comment" field that was collected on a web form. For a particular report we wanted to truncate this field to the first 1000 characters or so, but preserve valid HTML.
So I created a C# .dll & class with a public function:
public static string TruncateHtml(string html, int characters)
{
...
}
(I used the HtmlAgilityPack for most of the HTML parsing, and to create and close off my new HTML string, while I kept track of the content length.)
Then I could call that code with the fully qualified path to the function in an SSRS expression:
=ReportHtmlHandler.HtmlTruncate.TruncateHtml(Fields!Comment.Value, 1000)
I could have added a calculated field to my dataset with this, but I was only using this value for one field, so I kept it at the field expression level.
All of this code gets called well before the HTML is processed or rendered by SSRS. I'm sure that any original IMG tag will be in the string.
This approach might work for you, possibly create a ExtractImg function which could be set as the source of an img on the report. I think some of the tricky bits for your requirement will be to handle multiple images as well as embedding the extracted img. But you might be able to do this simply with a external reference to an image. I haven't done much with external images in SSRS.
An MSDN blog entry on calling a custom dll from SSRS: http://support.microsoft.com/kb/920769

Is it possible to export to CSV and have the header contain spaces?

I have a requirement for an SSRS 2005 report to be exported as a CSV, where the column headers contain spaces.
Currently the CSV header column titles are derived from the textBox property names and uses underscores instead of spaces. Is there another, better approach?
For example, currently I have:
SSRS Report Header : Effective Date
TextBox Name : Effective_Date
CSV Header: Effective_Date
I would like to have:
SSRS Report Header : Effective Date
TextBox Name : Effective_Date
CSV Header: Effective Date
Looks like its not possible, with a bit more digging I found the following Stack Overflow post:
SSRS csv export with comma in the column header names
I have solved this problem myself by customizing the built in CSV rendering extension to make it use the textbox's ToolTip property as the column header. The ToolTip property will allow spaces and other punctuation so gives you the flexibility to name the columns as you like. This also has the nice side effect of giving you a relevant tool tip, reminding you of what column you're looking at on a long report where the header might not be visible!
Note: In the designer, you set the ToolTip of the data row's textbox and not the header's textbox.
This isn't easily achieved because all the rendering extensions are marked as sealed classes. So to implement this, I used a decompiler and extracted all the code relating to CSV rendering into my own project. Then changed the line that writes the header text to read from the textbox's ToolTip property instead.
In the class named CsvColumnHeaderHandler you're looking for the method OnTextBoxBegin and in particular the line:
this.m_visitor.WriteValue(textBox.DataElementName, this.m_excelMode);
Simply change this to read:
this.m_visitor.WriteValue(textBox.ToolTip, this.m_excelMode);
This custom rendering extension can then be deployed to the report server and it works perfectly.
You wont need to know how to write a rendering extension for this because, as I said, I just copied (decompiled) the code. However, you will need to know how to deploy a custom rendering extension assembly. More information on deploying can be found here: https://msdn.microsoft.com/en-us/library/ms154516.aspx
There is a solution for this. You need to select in SSRS properties press F4,
select Properties, in that select particular textbox which you want to rename.
For example, let Textbox12 as a Effective_Date. Solution: Rename the Textbox with EffectiveDate.

sending sentences in url

This is an odd question but hopefully someone has an idea of how to work around it
I'm working with a 3rd party product that sends out txt-based emails on the triggering of certain events. I can customize the text of the emails and I have access to certain dynamic properties that I can embed that will be included when the email is generated. So for example assume that I have a dynamic property called %%full-name%%, when it sends the email it would substitute in 'John Smith' in the body of the email.
Now, I need to also embed a url in the email that uses that dynamic property, something like this:
http://mysite.com?fullname=%%full-name%%
but what will happen is that the 3rd party product has no idea I am embedding a link so it doesn't know to escape it for the space between John and Smith so I get this:
http://mysite.com?fullname=John Smith
where the clickable part of the link shows up as just the bolded part in most mail clients.
So my question is, is there a way to wrap that dynamic property such that it will render the link properly despite the spaces? Since its a 3rd party API I'm working with I have zero control over the actual values being passed into the dynamic properties so my options are limited
You should ask the third party vendor this questions. They may have some way of designating that you want a URL encoded dynamic variable in the email.
If you surround the link in quotes ("") or greater/less than (<>), most email clients "like outlook" will know that it represents one link and won't cut it off at the space.
"http://mysite.com?fullname=%%full-name%%"
<http://mysite.com?fullname=%%full-name%%>
You will run into issues if the variable contains other special characters (like: + % & " >).
edit *
Have you tried using HTML
http://mysite.com?fullname=%%full-name%%
If you control the data that is available, you could always maintain another property that is url-safe:
Hi, %%full-name%%, visit this link to set your preferences:
http://mysite.com?fullname=%%full-name-url%%"