BodyAsHTML Regular Expression Rules in Contextual Office Add-ins for Outlook No ratings yet.

Introduction

Outlook allows modern add-ins to be activated in contextual mode, meaning instead of showing a Taskbar or executing a function, they can be activated if a certain condition is evaluated as true within the body of an item.

This condition can be evaluated against the body as text, or body as Html. It’s the latter that this article will describe.

The problem

Defining a manifest with an ExtensionPoint of type ItemHasRegularExpressionMatch requires that one of the rules in the rule collection has the Highlight attribute set.

Defining only one Rule in the RuleCollection using BodyAsHTML as the property to scan, such as below example

<ExtensionPoint xsi:type="DetectedEntity">
    <Label resid="contextLabel"/>
    <SourceLocation resid="detectedEntityURL"/>
    <Rule xsi:type="RuleCollection" Mode="And">
        <Rule xsi:type="ItemIs" ItemType="Message"/>
        <Rule xsi:type="ItemHasRegularExpressionMatch" 
                      RegExName="OrderNumber" RegExValue="CO-\d{9}" 
                      PropertyName="BodyAsHTML" Highlight="none"/></Rule>
</ExtensionPoint>

will throw an error when validating the manifest similar to the one below:

A screenshot of a cell phone

Description automatically generated

The reason for this error is that in a RuleCollection, at least one of the Rules has to define the Highlight Attribute for the Outlook client be aware of what to highlight. Highlighting BodyAsHTML does not support Highlight=”all” due to the fact that some HTML parts may not be able to be highlighted, such as a <DIV>, <FORM>,  tags as an example.

For this reason, BodyAsHTML highlight attribute defaults to none, so specifying only one rule will cause the manifest to be rejected.

The Workaround

In order to avoid this error, BodyAsPlainText should be used as the highlight rule in order to get around this and the Highlight attribute should be set to “none” on the BodyAsHTML rule.

An Example of the RuleCollection using both BodyAsPlainText Rule AND BodyAsHTML rule in the collection. With this type of RuleCollection, the Manifest should pass validation.

<ExtensionPoint xsi:type="DetectedEntity">
    <Label resid="contextLabel"/>
    <SourceLocation resid="detectedEntityURL"/>
    <Rule xsi:type="RuleCollection" Mode="And">
        <Rule xsi:type="ItemIs" ItemType="Message"/>
        <Rule xsi:type="ItemHasRegularExpressionMatch" 
                      RegExName="OrderNumber" RegExValue="CO-\d{9}" 
                      PropertyName="BodyAsHTML" Highlight="none"/>
        <Rule xsi:type="ItemHasRegularExpressionMatch" 
                      RegExName="OrderNumbertext" RegExValue="CO-\d{9}" 
                      PropertyName="BodyAsPlaintext" Highlight="all"/></Rule>
</ExtensionPoint>

Additional Information:

0

Please rate this

Leave a Reply

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