I’ve been banging my head on my desk about this, feel free to reproduce the test and join me headbanging…
The Situation:
I have an application with a button “Mail Report”.
This button should do the following things:
– Create a new document in your mail database (without saving it)
– Pre-populate some fields (including the body)
– Add an attachment to the mail body
– Open it in the UI and let the user decide to send/save/discard it.
The Problem:
Assembly of the rich text field using Append… calls fails, unless (get this):
– The agent runs in debugger
– The agent is stopped in the debugger after the code which does the appending and before the code actually displaying the order.
Since it is probably simpler to understand when you see this for yourself, feel free to setup a small test environment.
-
Create a text file in the root of your C: drive called “test.txt”.
-
Create a new test database.
-
In the database, create a form named “Test”, with one single field “Body” (type: rich text, editable).
-
Create an agent named “Test” (event: menu selection, target: none). Copy the code below in your agent.
-
Run the agent normally
→ Nothing is appended in the body item, attachment is in a $FILE field.
- Run the agent in the debugger and hit ‘continue’
→ Nothing is appended in the body item, attachment is in a $FILE field.
- Run the agent in the debugger and step through the code
→ The body is populated as it should be populated, including the attachment.
- Run the agent in the debugger, step through the code until you reach the call item.AddNewLine(2) call, then hit ‘continue’.
→ The lines through which we stepped in the debugger are added properly, the others aren’t. The attachment is added in a $FILE field
- Run the agent in the debugger, set a breakpoint on the ws.EditDocument call, hit ‘continue’ twice.
→ The body is populated as it should be populated, including the attachment.
I’ve been racking my brain about what could be going wrong:
– There is a timing issue between the back-end and the frond-end (but why would the attachment be visible in a $FILE field???)
– The debugger does some extra calls somewhere to show the variables, which triggers this behaviour.
Up until now, I can’t find out what’s going wrong. Any suggestions?
Cheers,
Bram
---- Agent Code: Sub Initialize ----
' Declarations
Dim ws As New NotesUIWorkspace
Dim session As New NotesSession
Dim doc As NotesDocument
Dim db As NotesDatabase
Dim item As NotesRichTextItem
' Get context db
Set db=session.CurrentDatabase
' Create new document + empty rich text item
Set doc=db.CreateDocument
doc.form="Test"
Set item=doc.CreateRichTextItem("Body")
' Append stuff to rich text item
Call item.AppendText("Line 1")
Call item.AddNewline(1)
Call item.AppendText("Line 2")
Call item.AddNewline(2)
Call item.AppendText("Line 3")
Call item.AddNewline(3)
Call item.EmbedObject(EMBED_ATTACHMENT, "", "c:\test.txt")
' Open document in UI
Call ws.EditDocument(True, doc)