Workarounds For Blocked Html Markup In Sharepoint Calculated Columns

What Gets Blocked and Why

SharePoint calculated columns do not allow the use of HTML tags or JavaScript code. These markup languages get filtered out and blocked for security reasons. SharePoint is designed to prevent the injection of potentially malicious code into sites and libraries. The platform’s automatic input validation strips out anything that looks like unsafe HTML or script.

Tags like <b>, <i>, and <a href=””> get removed even though they seem harmless. This is because the SharePoint engine does not actually parse the input to determine if it has dangerous constructs. For performance and scalability, SharePoint uses a simple allow-list based filter. Any input that contains HTML tags, JavaScript functions, etc gets sanitized. This blanket filtering ensures that SharePoint environments remain secure as they scale to handle large volumes of content and users.

Workarounds Using Custom Formulas

Although most HTML and JavaScript gets blocked in SharePoint calculated columns, it is possible to workaround these restrictions using some custom formulas. The basic approach is to swap out the actual markup tags with SharePoint-friendly placeholders and formatting functions. For example:

  • Use the SUBSTITUTE() formula to replace angle brackets with other symbols
  • Use the CONCATENATE() formula to piece together text snippets without spaces

If you need to make some text bold within a calculated column, instead of using <b>, you can swap out those tags for placeholder tokens like !! and !!. Then use the SUBSTITUTE() formula to wrap the target text in those token pairs. For example: SUBSTITUTE(“This needs to be bold text”, “needs to be”, “!!needs to be!!”). This replaces “needs to be” with the token pairs. The column would render it as bold.

Similarly, you can use CONCATENATE() to append strings together without spaces. This lets you build up an linked phrase without angle brackets. Like: CONCATENATE(“Contoso Intranet“)

Encoding Tricks to Avoid Filters

In addition to substitute formulas, calculated columns also support HTML character encoding. This allows substituting angled brackets and other blocked markup with their decimal character code equivalents. The SharePoint filters allow these numeric encodings through since they appear innocuous. Some common examples include:

  • < for <
  • > for >
  • <b> for bold tag

Though clumsy looking, HTML encoding can be an effective tactic for sneaking some styling into SharePoint calculated columns. The raw codes may show in edit screens, but they render properly for end users. And the filter allows them since only numbers and ampersands appear in the formulas. Hex encoding also works using the &#x format.

Embedding Content with External Tools

When custom formulas and encodings prove inadequate, SharePoint provides some external tools for bypassing the calculated column restrictions. The Script Editor and Content Editor web parts can be leveraged to embed arbitrary HTML markup into pages.

Since these web parts access the underlying ASPX code, they sidestep the input filters applied to other SharePoint components. Content authors can inject scripts and styling not otherwise allowed. For example, adding a Script Editor with some JavaScript opens the door for more powerful formatting logic. The Content Editor web part also gives full control over the HTML sent to the browser.

Accessing these web parts requires designer-level permissions. But they provide an unrestricted canvas for formats that calculated columns filter out. Examples include:

  • Enabling the Script Editor, then adding JavaScript functions to shape rendering
  • Using the Content Editor to externalize HTML snippets

This does move the complexity out of list definitions and into page rendering. But in some advanced scenarios, that tradeoff enables formats that cannot be achieved otherwise.

When to Use Alternate Solutions

Despite crafty workarounds with formulas and encodings, many SharePoint experts recommend using alternate solutions for complex display logic.

For example, creating filtered List View Web Parts allows fine-grained control over Rendering Templates. Custom display templates can include almost any HTML formatting needed. This achieves rich rendering while keeping that complexity in a safe container outside of list definitions.

For simple text styling needs, the Content Editor web part also offers a quick way to inject HTML without getting into custom code. Authors can style content freely without worrying about restrictions that apply to calculated columns and other platform components.

Finally, migrating advanced scenarios into PowerApps can sidestep restrictions altogether. PowerApps provides almost unlimited customization potential with the ability to query SharePoint lists dynamically. By taking dependency on calculated columns out of the picture, PowerApps solutions can integrate rich UI formats safely.

As with Script Editor, these techniques require more expertise than pure calculated column formulas. But sometimes that additional complexity pays dividends in terms of output flexibility and security.

Leave a Reply

Your email address will not be published. Required fields are marked *