Saturday, October 1, 2011

How to hide attachments in Hide-Whens

A few moments with Designer, and I had a test form and a computed subform, controlled by a checkbox and a computed subform value based on that checkbox. When checked, the subform was included, and the attachment appeared as expected in the rich-text field. When not checked, the subform wasn't included, and the attachment appeared in V2 format.

I then added a header to the main form, leaving all the options for the header defaulted, and the attachment appeared in the header instead -- as part of a standard section. So far so good. I was now in control of where the attachment appeared.

Now I started to work with the attributes on the header itself, which you can also see in Figure A:


Here are the attributes. (click for larger image)

I set Height to 1 pixel. Since taking the screenshot, I've also tried 0. That works too. I set Scrolling to No and I set Border size to 0. Once that was done, the document opened without displaying the attachment.

The key is making the header small, 0 or 1 pixel, so that there just isn't the space for Notes to render the attachment icon. I had some text in the header -- you can see that in Figure A -- so that I could see where the header appeared.

Once I was happy, I just added a Hide-When -- Hide from Notes 4.6 and above -- to it to make it vanish for display.

Andy also said that these ideas had solved a different but related problem with a simple and effective solution:

I was able to meet another request by using a slightly different take on your code. The users wanted some people to be able to see/open the attachments but not be able to add or delete attachments. I added two subforms, both had a rich-text field with the same name. On one subform the field is editable and on the other the field is computed.

Do note a couple of things about these ideas.

First, this is a Notes client application solution. On the Web, attachments don't display if the rich-text field isn't displayed. If you do have V2-style attachments in the document, adding field $v2AttachmentOptions with a text value 0 ("0") will prevent them from displaying. That's a classic Domino Web issue, and doesn't affect XPages, by the way.

Second, this solution has no selectivity. It's an all-or-nothing solution. If there are any file attachments on the document, and the field that they are attached to isn't displayed for any reason, Notes will place them in the form header, if there is one, or as V2-style attachments. If you add a header as discussed above, it will control all the attachments whose anchor rich-text field isn't displayed.

Finally, this solution may stop working in future releases of Notes. It's not documented anywhere that a header controls the display of orphan attachments, but Lotus do use the behaviour in the mail template, so I suspect that it's here to stay.

If you'd like a copy of the sample database that I created, just email or Skype me. Email is below, and I'm sure you'll be able to find me on Skype.