Force Saving UI Document Through Action for Check Attchment in Rich Text

Force Saving UI Document Through Action for Check Attchment in Rich Text

On some occasions, you want to force users to Save UI-document by pressing some button to check documents.

I was faced this occasion to check if some Rich-Text fields contains attachment files, and check their sizes and extensions. The files that attached last time cannot handle(even see) in back-end class(notesDocument)until UI documents is saved.

I solved this problem by using this code and "SaveOptions" field.

If you use "SaveOptions" field only, user can close UI-document accidentally by pressing [ESC], and avoiding this, you must create some validating-field, set some value in this field in actions, and that is not smart.

This code is used for Form-Action-script only, but I think it's very useful.


Form has "SaveOptions" field, text, editable, keyword "1" or "0".

(Form Globals)
'Check if action button is pressed. True or False
%Include "lsconst.lss"
Dim ButtonPressed As Variant

(PostOpen)
'Initialize variant above
ButtonPressed = False

(QuerySave)
'Check if button pressed If Not ButtonPressed then
Msgbox "You must press 'Save' button for save this document.",
MB_OK+MB_ICONSTOP, "Save Notify"
Continue = False
End If

(Some Form-Action button)
Dim workspace As NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim note As NotesDocument
Set uidoc = workspace.CurrentDocument

On Error GoTo ErrorHandler

'button is pressed
ButtonPressed

    Requires Free Membership to View

    Register today to access targeted resources from our editorial writers and independent industry experts focused on Lotus Domino, Notes, Workplace and other related technologies.

    By submitting your registration information to SearchDomino.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchDomino.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

= True

'Refresh UI-document without save
Call uidoc.FieldSetText("SaveOptions", "0")
Call uidoc.Save

'Get backend note
Set note = uidoc.Document

'Code some checks.
'e.g. I wrote here to check richtext has embedded items.
' 1.Allow only file-attachment, deny Object/Object Link,
' 2.Allow only BMP files.
Dim rtitem As Variant
Dim objs as Variant
Set rtitem = note.GetFirstItem("Body")
If rtitem.Type = RICHTEXT Then
Set objs = rtitem.EmbeddedObjects
If Not IsEmpty(objs)
Forall obj In Objs
If obj.Type <> EMBED_ATTACHMENT Then
Msgbox "You can attach only files in this field."
Goto ErrorHandle
End If
If UCase(Right(Obj.Name, 3)) <> "BMP" Then
Msgbox "You can attach only BMP files in this field."
Goto ErrorHandle
End If
End Forall
End If
End If

'Save backend note
Call note.Save(True, True)

'button check clear
ErrorHandler:
ButtonPressed = False

This was first published in November 2000

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.