When a rich text item is updated in the current document using LotusScript, the changes are not immediately visible on the screen. In order to see the rich text that has been added, a user must first save the document via script, quit out of the document and then reopen it. Is it possible to automate this process using Script?
The sample script below illustrates one way to automate this process. The script works as follows:
1. Creates (in the current document) a new Rich Text field named "RT."
2. Attaches the specified file to this Rich Text field.
3. Stores the current document's "Subject" in the "SearchDoc" variable.
4. Sets (through back end classes) the "Form" field and then saves the document.
5. Gets a handle to the view called "Main" and refreshes the view's index through both
the front end and back end classes, so the new document will display in the view.
6. Sets "SaveOptions" in the current document to "0" (so the user will not be asked to
save the document) and then closes the document.
7. Using the OpenDatabase method, opens the "Main" view (which is categorized by
"Subject") and highlights the appropriate document (based on the "Subject").
8. This document is then reopened using the EditDocument method, and "SaveOptions" is
set back to "1".
2. Attaches the specified file to this Rich Text field.
3. Stores the current document's "Subject" in the "SearchDoc" variable.
4. Sets (through back end classes) the "Form" field and then saves the document.
5. Gets a handle to the view called "Main" and refreshes the view's index through both
the front end and back end classes, so the new document will display in the view.
6. Sets "SaveOptions" in the current document to "0" (so the user will not be asked to
save the document) and then closes the document.
7. Using the OpenDatabase method, opens the "Main" view (which is categorized by
"Subject") and highlights the appropriate document (based on the "Subject").
8. This document is then reopened using the EditDocument method, and "SaveOptions" is
set back to "1".
Sample Script:
Sub Click(Source As Button)
Dim w As New notesuiworkspace
Dim s As New NotesSession
Dim db As notesdatabase
Dim uidoc As notesuidocument
Dim view As notesview
Dim object As notesembeddedobject
Dim doc As notesdocument
Dim col As NotesDocumentCollection
Dim searchdoc As String
Dim DT As New NotesDateTime("1/1/50")
Set db = s.currentdatabase
Set uidoc = w.currentdocument
Dim rtitem As Variant
Set doc = uidoc.Document
'Create New RichTextItem in the current document
Set rtitem = New NotesRichTextItem(doc,"RT")
'Attach the bitmap
Set object = rtitem.EmbedObject ( EMBED_ATTACHMENT, "", "c:\temp\access.txt",
"Att" )
'Get the key value from the current document
searchdoc = doc.subject(0)
'Set the form field and save document through backend
Doc.Form = "Add Rich Text through UI"
Call doc.save(False,False)
'Refresh the main view through back end and front end methods
Set view = db.getview("Main")
Call view.Refresh
Call w.viewrefresh
'Set save options to zero so that user does not get prompted to save after closing
uidoc
doc.saveoptions = "0"
Call uidoc.close
'Open database to main view, find the document again based on searchdoc and open it
up
Call w.OpenDatabase("","","Main",searchdoc,False,True)
Set uidoc = w.Editdocument(True)
'Reset doc and set saveoptions back to "1"
Set doc = uidoc.document
doc.saveoptions = "1"
End Sub
The file (RT.NSF) is a sample database that contains a sample script that adds an attachment
to a rich text field in the current document and then saves, closes and reopens the document
- so the attachment is visible on the screen.
to a rich text field in the current document and then saves, closes and reopens the document
- so the attachment is visible on the screen.
How to use:
Before using the sample database, you must take the following steps to customize the code:
1. Detach the database.
2. Edit the "Add Rich Text through UI" form.
3. Click on the button, and (in the programmers pane) switch to the click event.
4. Edit the path and file name in the following line of code to point to a valid file on
your hard drive.
2. Edit the "Add Rich Text through UI" form.
3. Click on the button, and (in the programmers pane) switch to the click event.
4. Edit the path and file name in the following line of code to point to a valid file on
your hard drive.
Set object = rtitem.EmbedObject ( EMBED_ATTACHMENT, "", "c:\temp\access.txt", "Att" )
5. Save and exit the form.
To test out the database:
1. Compose a document using the "Add Rich Text through UI" form.
2. Enter a unique subject.
3. Click the button. The script will then attach the file, save, close and reopen the
document so that the attachment is visible on the screen.
2. Enter a unique subject.
3. Click the button. The script will then attach the file, save, close and reopen the
document so that the attachment is visible on the screen.
No comments:
Post a Comment