Embedding HTML in Attributes

Since MicroStrategy is primarily consumed via the Web, there is a unique opportunity to embed some extra value by slipping HTML into little pockets of a report.  While the HTML Container for Documents is obviously designed to do just that, you can also sneak it into Attributes which can help solve some pretty neat problems.  Today I’ll talk about how HTML Attributes work and a few use cases.

All of these tricks are going to be built off of the simple technique of using ApplySimple’s in Attribute Form definitions.  An ApplySimple is a Database Passthrough Function, which allows you to custom build the SQL for the Attribute Form.  We’re going to use that to generate some HTML code that will eventually be rendered on the Web.

Secondly, regardless of what Data Type the underlying column or columns are, we’ll need to choose HTML Tag as the Attribute Form Type.  This is a signal to MicroStrategy that we’ll be returning HTML so that it can be sure to parse it correctly.

It’s also important to note that since we’re embedding HTML, consuming the report through anything other than Web (Desktop, Mobile, Office) won’t properly resolve the HTML and will instead display the ugly code.  Flash mode supports a few of the basic formatting tags, so there could be some hope there.

Adding Images
One of my favorite tricks is to use this to add Pictures to reports.  While there is an Attribute Form Type specifically for Pictures, I highlighted a use case in the Report Search Tool post where you’d want to have the image and text side by side.

To implement this, we just need to build the simple HTML string to use the <img> tag and append the text afterwards:

ApplySimple("'<img src=' + #0 + '>&nbsp;&nbsp;' + #1", [Object_Image], [Object_Desc])

In this example, the database contains the column Object_Image which contains the URL to the image.


Formatting Attributes Selectively
Since Thresholds can currently only be applied to Metrics, you may need to turn users away if they ask to custom color code Attributes.  While you can sometimes get away with slipping the Attribute into a Metric using a Max() function or similar, that’s not always an option.  Now, you could add an Attribute Form that has the conditional formatting logic built in:

ApplySimple("case when #0 = 'chicago' then '<font color=red>' + #0 + '</font>' else #0 end", [City])

It’s not an ideal solution since making changes requires schema changes, but in a pinch it could solve the problem.

Javascript Alerts
I’ve had to do reports in the past where there was a long text field that had to be displayed with the report, like a Comment or something.  It’s really ugly to have giant walls of text in the grid, so a quick solution was to modify the Attribute to show a link for “Details” that pops up a window containing the long text.  This makes the Report a little more interactive and somewhat better looking.

ApplySimple("'<a href=javascript:alert(''' + #0 + ''');>Details</a>'", [RegionName_FR])

In this example, clicking the Details link next to Mid-Atlantic shows the French version of the name.

Element Tooltips
An alternative to the popup option from above, you could also embed the information in a tooltip:

ApplySimple("'<abbr title=''' + #1 + '''>' + #0 + '</abbr>", [Region_Name], [Region_Name_FR])

In this example, hovering over the Mid-Atlantic name pops up the French name in the tooltip.

You may also like...