Saturday, October 1, 2011

How to hide attachments in Hide-Whens


By Mick Moignard

A couple of years back we ran an article about the issues of Hide-Whens and rich-text fields.

In a nutshell, the issue is that you can't hide rich-text fields properly just by using Hide-Whens, because the Hide-When formula is inherited into the rich-text content when you start to use the field, and stays there, acting independently of the form's Hide-Whens.

To make matters worse, pasted content won't be subject to the form's Hide-When either, and that brings even more pain if the pasted rich-text comes from another Notes field and itself contains other Hide-When formulas.

The solution I offered uses subforms to contain the rich-text fields, and inserting those subforms as computed subforms to control whether the rich-text field is included in the display or not. You can read the complete gory details at in How hide-whens in Rich Text can ruin your whole day (and what to do about it).

The attachment problem

However, as reader Andy Pisano recently emailed me, that solution doesn't work if the rich-text field content includes attachments. He said that the attachment appeared at the bottom of the document under a horizontal line. This display of attachments is what's known as V2 style, named such because that's how Notes 2 handled attachments.

Notes also uses V2-style attachment display if the attachment isn't actually anchored inside a rich-text field. As Andy points out, it also does this if the attachment is anchored in a rich-text field but the rich-text field isn't included in the form/subform collection used to display the document. Andy didn't want that to happen. And neither he nor I could find a way to prevent Notes displaying the V2 attachment.

Until now.

The trigger to a solution key was actually a Technote, Attachments appear in the header section of a memo or form.

It noted that, in some circumstances, attachments are displayed in the header of a mail message. It also noted that this only happens when the attachment isn't attached to a specific field in the mail item. The key phrase was "This only occurs in cases where the form design contains a header, and when the attachment was added to the document rather than added to a particular field."

In Andy's case, the attachment was part of a field. But we had the circumstance where the field wasn't actually part of the displayed form, because the subform wasn't included by the formula. So Notes appeared to be treating the attachment as part of the document instead, and displayed it in the V2 style.

I wondered whether, if I added a header to the form, whether the attachment would appear there instead, and if that would then give us control over whether and how it was displayed.