Learn how to a build a cloud-first strategyRegister Now


Trying to use Computed SubForm & DialogBox as workaround to Rich Text Fields & Hide When Formula issues - HELP!

Posted on 2007-07-31
Medium Priority
Last Modified: 2013-12-18
I have built a form that relates to a product. The product consists of between 2 & 4 PDF files, depending on the answers to various questions on the form. As the form is filled in, certain sections & questions dynamically appear and disappear, as not all questions apply to all products. This is achieved with various hide-when formulae.

The problem is with the Rich Text Lite fields I am using to store the PDF files. As you may or may not know, there is an issue with hiding Rich Text fields using Hide When formulae. It's something to do with the paragraph(s) contained in the Rich Text field actually taking on the Hide When formulae for itself, rather than just the field displaying or not. Anyway, the recommended workaround involves placing the Rich Text field on a computed subform, rather than directly in the main Form. But the trouble is, this only hides or displays the field when the Document is opened. So answering the questions so that one should appear or disappear doesn't take effect unless you close & re-open the Document.

I have thought of a solution to this, but seem to be having great difficulty in getting it to work. The solution involves placing the Rich Text fields on Computed Subforms, but displaying these on a separate Form displayed in a DialogBox. Cool, huh? Initially I thought I'd have to have an Action Button & associated DialogBox Form for each of the four Rich Text fields, but as this Document is created when you press the Action Button, the Computed Subform trick works a treat, hiding & displaying each field correctly at the time the DialogBox is displayed.

Now here's the problem. NotesUIWorkspace.DialogBox() can be called using the existing Document, or using an alternative NotesDocument. If I use the existing Document, then any existing PDF files are brought from the underlying Document & displayed in the correct field in the DialogBox. But, when I press OK, instead of being saved back to the field from whence it came, it gets attached to the bottom of the Document, below all the fields. And from there I can't seem to find it in LotusScript, & even if I could, I'd have no way of knowing which file was which. If, on the other hand, I create a new NotesDocument in the LotusScript, then display that using the DialogBox, then I can't seem to get any existing PDF files from underlying Document & display them in the DialogBox in the first place. And I dare say I will have the same problem trying to get it back out & into the underlying Document again. The reason is that I can only seem to attach a file from an actual file in the filesystem, & extracting it then attaching it again seems very inefficient.

I've now just tried to get it to work using NotesItem.CopyItemToDocument, to copy the files between the two Documents, but I can get it to go into the DialogBox, but not back again.

Does anyone have any idea how I can solve this?

Here's my current code from the Action Button:

Option Declare

Sub Click(Source As Button)
 Dim session As New NotesSession, dbThis As NotesDatabase
 Dim ws As New NotesUIWorkspace, uiDoc As NotesUIDocument
 Dim strComponents(3) As String, docProduct As NotesDocument, docDialog As NotesDocument, rtiProduct As NotesRichTextItem, rtiDialog As NotesRichTextItem
 Set dbThis = session.CurrentDatabase
 Set uiDoc = ws.CurrentDocument
 strComponents(0) = "PDF1"
 strComponents(1) = "PDF2"
 strComponents(2) = "PDF3"
 strComponents(3) = "PDF4"
 Set docDialog = dbThis.CreateDocument()
 Call uiDoc.Save()
 Set docProduct = uiDoc.Document
 Forall c In strComponents()
  Call docDialog.ReplaceitemValue(c & "Status", docProduct.GetItemValue(c & "Status")(0))
  Set rtiProduct = docProduct.GetFirstItem(c & "File")
  If Not Isempty(rtiProduct.EmbeddedObjects) Then
   Set rtiDialog = rtiProduct.CopyItemToDocument(docDialog, c & "File")
  End If
 End Forall
 If ws.DialogBox("dialogSubmitFiles", True, True, False, False, False, False, "Submit/Edit/Resubmit Source File(s)", docDialog, True, False, False) Then
  Forall c In strComponents()
   Set rtiDialog = docDialog.GetFirstItem(c & "File")
   If Not(rtiDialog Is Nothing) Then
    If Not Isempty(rtiDialog.EmbeddedObjects) Then
     Set rtiProduct = docProduct.GetFirstItem(c & "File")
     Call rtiProduct.Remove()
     Set rtiProduct = rtiDialog.CopyItemToDocument(docProduct, c & "File")
     Call docProduct.Save(True, False)
    End If
   End If
  End Forall
  Call uiDoc.Reload
 End If
End Sub
Question by:PaulCutcliffe
  • 6
  • 3
  • 2
  • +1
LVL 22

Expert Comment

ID: 19605213
Sorry to burst your bubble, but...

Richtext is not supported via DialogBox.  From the designer help file for NotesUIWorkspace.DialogBox:
"Field sharing is not supported for rich text fields."

I have given up on storing file attachments directly on my forms.  I find it much easier to store them in a separate document, and manage them using LotusScript.  That way I have total control over the files.

Author Comment

ID: 19607123
Bill-Hanson: So how do you store & retrieve them?

In my applicaton, the system needs to allow the user to submit 2, 3 or 4 PDF files, depending on the type of product. Then, they or another user need to be able to retrieve the files, edit them & replace the stored file with the edited version. Then when somebody changes the status & close the Document, the Form.Terminate event calls an Agent on the server which extracts the files & stores them on the server's disk.

When a new Product is first created, it is not known how many files there should be until various questions on the Form have been completed. This is why I originally had trouble with the Rich Text fields being on the main Document Form, & hiding/displaying them as necessary with Hide When Formulae.

I think ideally it needs to be able to allow the user to submit the files via an Action button, hence this idea with the DialogBox.

Can you or anyone else think of any other way to do this?

Expert Comment

ID: 19607293
You could use your original method with the computed subforms. You just need to reload the document, to display them.

I assume on the selection-fields you have 'refresh fields on keyword change' checked.

Then in the PostRecalc you could use this script:
Dim w As New notesuiworkspace
Dim doc As NotesDocument

Set doc=source.Document
Call w.EditDocument(True, doc)
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 22

Expert Comment

ID: 19608400
First off, Joe is right about being able to reload the form to force the computed subforms to display properly, so you may want to try that approach.  A warning, though.  The form event timing is a little hard to predict; especaily if you have complicated controls on the form that also need to be updated or refreshed when the form is saved (like programatic tables or embedded views that need to be reloaded, etc).

My problem with using RichText for file storage on the form is based on several reasons, many of which may not apply to your application.  Here are my main reasons for switching to separate documents:

(1) Can't use RichText fields to upload files via a web browser.
(2) You would need complicated LotusScript code to place restrictions on the RichText such as the number of attachments per field or the type of objects you can store (especially before RichTextLite came along).
(3) I can provide my own controls for manipulating the attachment.
(4) I can provide my own display for showing the attachments.

I use a class that manages the file attachments.  The class has methods for Add, Edit, Open, Delete, Save, Email, and many other methods (such as sending a file to a repository).  The class uses standard forms and views to store and retrieve the file documents.  Each file document contains the UNID of the main document, along with any identifying attributes (such as category).  The class enforces certain rules (like only one file per main document, or only one file per category, or any other rule).

The drawbacks using this technique are:

(1) You have to write alot of code to make this work, but once the code is written, you can use it in any database.
(2) That's all I can think of.

From time to time, I do allow a file to be embedded directly in the NotesDocument, but I still provide my own controls and displays on the form.  The RichText field is always hidden, and any work on the attachment is done in the backend with the form closed; like this:

Dim doc As NotesDocument
Set doc=source.Document

' Manipulate richtext fields here...

Call w.EditDocument(True, doc)

Author Comment

ID: 19610693
Hmmm. This needs some rethinking. I'm not wokring tomorrow, so I'll have to come back to it in a few days.

Thanks for your contributions.
LVL 31

Accepted Solution

qwaletee earned 2000 total points
ID: 19616533
Or, you coudl always take the easy way out and 1) trust the users a little, and 2) provide a slightly less rich UI.

Just leave the fields open, and suggest to users when they shoudl be placing PDFs into the fields.

There are TWO other options.  Some background: The problem with rich text fields is that a form is merely a very fancy rich text field.  When you place rich text fields on a form, what the user is really interacting with is two levels of rich text -- the form, and the rich text field embedded in the form.  The Rich Text field has its own rich text attributes which can conflict with the form's.  Since the rich text field is processed AFTER the form is processed (because it loads within the form, after the form loads), its attributes generally override those of the form. Now, when you opena  brand new form, the rich text field INHERITS the attrobutes of the spot on the form where it was placed, but afterwards it maintains itself independently. You now have rich text attributes divorced from the form, and overriding the form.

So what are the two options?

1) There is one time when a rich text field's attributes  CAN'T override the form's attributes.  That's when the ruch text field is not placed at the start of a paragraph.  Notes can't override the paragraph attributes once they are rendered, so if there is even a single space or tab on the line of the rich text field, to the left of it, the paragraph attrinuutes will not later be overriden by the rich text field.  (If the user adds a paragraph to the rich text field, it gets a little more ocmplicated).

2) You can try playing with a hidden section, and the collapse/expand sections command.  The content INSIDE the section doe snot have any hiding attributes, just the section itself.  When the section is collapsed and hidden, it effectively hides its contents.  When expanded, its contents show.
LVL 22

Expert Comment

ID: 19617028
Quote:  "1) trust the users a little".

I did that once  :)

Then, about 4 or 5 years later, we migrated that database to a relational system, and since we had no control over the file attachments, it was very dificult to port the data (of course that was before richtext lite).

Just my 2 cents.

BTW: I have used the section trick in the past (#2 from 19616533) and it seems to work well.  If time is important, you may want to try that first.  My solution requires ALOT of ground work.

Author Comment

ID: 19623925
Bill-Hanson said:

>> My solution requires ALOT of ground work.

Unless you were to provide this class? :-)

No? Ah well, it was worth asking! ;-)

Author Comment

ID: 19623958
qwaletee, I'm definitely going to play around with the hidden sections idea. And I could also just display all the fields at the bottom, then on saving, check that the user hasn't supplied files that are not needed, & point this out if they have.

I do like elegant solutions, though, which is why I was so keen on the DialogBox idea, as everything can then be controlled with Action buttons, which of course you can hide & display at will. I was gutted that you couldn't get the contents back out of the DialogBox document & into the main one again.

Author Comment

ID: 19625969
qwaletee, you are (as ever!) a star!

By adding a space to the start of the paragraph, it seems that, as you correctly stated, the Hide-When formulae work correctly. This means I can strip out all this complicated stuff & place the Rich Text Lite fields (preceded by a space!) in the table along with all the Text fields, & as parts of the form appear or disappear, so do they! Perfect!

I'm now going to re-engineer my form back to how it was before I started out on this futile mission, only to add a few strategically placed spaces. And I've even made the field line up correctly despite the extra space, by adjusting the left margin!

I wish I'd known this before, but hey, at least I know it now!

Author Comment

ID: 19625994
Thanks for everyone else for their contributions, but I have to award the points to qwaletee for his beautifully elegant solution.
LVL 31

Expert Comment

ID: 19673439
Note: If the user adds additional paragraphs of rich text, they will get their own hide properties.  But you can trap that to some extent.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question