LotusScript AddNewLine

Hi there

I have tried every which way to get a new line insert to no avail - it just happily skips through the code and no new line. If anyone can point me in the right direction I’d appreciate it…

Here’s the offending code

Sub Querysave(Source As Notesuidocument, Continue As Variant)

Dim session As New NotesSession	

Dim doc As  NotesDocument

Dim rtItem As NotesRichTextItem

Dim db As NotesDatabase

Set db = session.CurrentDatabase

Set doc = Source.Document

Set rtItem = doc.GetFirstItem("Log")	

Call rtItem.AddNewline(1)	

Call source.FieldAppendText( "Log", " " )

Call source.FieldAppendText( "Log", Cstr( Date ) )

Call source.FieldAppendText( "Log", " " )

Call source.FieldAppendText _

( "Log", session.CommonUserName )

Call rtItem.AddNewline(1)

Call source.FieldAppendText( "Log", " " )

Call source.FieldAppendText _

( "Log", source.FieldGetText( "Updates" ) )

Call source.FieldClear( "Updates" )

Call source.FieldClear("Current_Date")

Call source.FieldClear("User")

End Sub

Subject: LotusScript AddNewLine

Some 12 hours spent on this and still zilch

Here is latest - I’ve included a new clipboard class and set up a dummy form

Sub Querysave(Source As Notesuidocument, Continue As Variant)

Dim workspace As New NotesUIWorkspace

Dim x As WindowsClipboard

Set x = New WindowsClipboard()

Dim session As New NotesSession  

Dim uidoc As NotesUIDocument	

Dim DummyUIDoc As NotesUIDocument 

Dim db As NotesDatabase 

Dim DummyDoc As NotesDocument  	

Dim DummyRT As NotesRichTextItem 	

Dim vString As Variant



Set db = session.CurrentDatabase 

Set uidoc = workspace.CurrentDocument 		

Set DummyDoc = db.CreateDocument 

DummyDoc.Form = "Dummy Form" 

DummyDoc.SaveOptions = "0"

Set DummyRT = New NotesRichTextItem(DummyDoc,"DummyRT")	

Call DummyRT.AppendText(session.CommonUserName & " - ")

Call DummyRT.AppendText(Cstr(Now))

Call DummyRT.AddNewline(1)

'Get the new log update

Call uidoc.GotoField("Updates")

Call uidoc.SelectAll

Call uidoc.Cut

vString = x.Contents

Call DummyRT.AppendText(vString)	



Call DummyRT.AddNewline(2)

'Get the old log entries

Call uidoc.GotoField("Log")

Call uidoc.SelectAll

Call uidoc.Cut

vString = x.Contents

Call DummyRT.AppendText(vString)

Call DummyRT.Update

Set DummUIDoc = workspace.EditDocument(True, DummyDoc)   <--------------------- SCRIPT BLOWS UP HERE

Call DummyUIDoc.GotoField("DummyRT")

Call DummyUIDoc.SelectAll 

Call DummyUIDoc.Copy

Call DummyUIDoc.Close(True)	

Call uidoc.GotoField("Log")

Call uidoc.Paste 

End Sub

The code fails at the higlighted point with “Cannot locate form: Dummy Form” - when that box is closed another pops up with “Notes Error - Cannot locate default form”

Since my eyes now look like Uncle Fester it’s time to spend an hour or two with the family. If anyone knows a solution…

Subject: RE: LotusScript AddNewLine

There are a certain number of previous posts here about these error messages. You can often get an answer faster by searching.

I don’t understand why you think your problem has anything to do with AddNewLine.

The message “Cannot locate form” means that Notes (and the EditDocument method in this case) cannot locate a particular form. Since you have assigned the Form item of the document to “Dummy Form”, it would be safe to assume that Notes is looking for a form with that name. Is there in fact such a form in your application? If so, is there anything unusual about it that might prevent the user running this code from opening it in the current context? A compose access list, for instance, or a language setting, or a client selection (notes/web/mobile)?

Failing to find a “Dummy Form” form that is usable, Notes looks for a default form to use as an alternate. However, you haven’t defined one. See blog entry Default form, how necessary? for more information about this.

Subject: RE: LotusScript AddNewLine

“There are a certain number of previous posts here about these error messages. You can often get an answer faster by searching.”

This was just a ‘by-product’ of the AddNewLine issue (1st thread) and my searching for a solution.

“I don’t understand why you think your problem has anything to do with AddNewLine.”

This is where it all started - just trying, without success, to insert a new line…

“The message “Cannot locate form” means that Notes (and the EditDocument method in this case) cannot locate a particular form. Since you have assigned the Form item of the document to “Dummy Form”, it would be safe to assume that Notes is looking for a form with that name.”

The first part of the code creates the form and seems to quite happily add data to the also created RichText field - so it’s a puzzle as to how it 'loses; it thereafter…

“If so, is there anything unusual about it that might prevent the user running this code from opening it in the current context? A compose access list, for instance, or a language setting, or a client selection (notes/web/mobile)?”

It’s created within the same code block!

I am more of a VB.Net programmer, and whilst LotusScript does resemble VB in a lot of ways I am trying to get my head round some new concepts…

I just need a solution to insert a new line… The code in the first thread did everything else, thereafter it’s been a going roound in circles event…

Subject: RE: LotusScript AddNewLine

Your problem in your original post:

During the Querysave event, the rich text in the front end is not yet available in the back end (unlike non-rich text fields). Updating the rich text in a back-end NotesDocument, and getting it to display in a document you are editing at the time, is a little tricky – one method is described here: Update rich text tip. You will not be able to do this during the Querysave event, however – it’s more for action buttons and the like.

You are better off using the NotesUIDocument methods – but you can’t mix them with back-end methods, because back-end changes are not immediately reflected in the UI.

You can insert a line break into some rich text using, for instance:

Source.FieldAppendText “fieldname”, {

}

This is not the same as a paragraph break, but I suspect it will be good enough for your purposes.

As for your followup post, it appears you are having some difficulty with the terminology. The code you posted does not create a form. It creates a document. A form is something you create using Domino Designer. To open a document on screen, as you are attempting to do on the line that gets the error, you must have a form to control the appearance of the document and what fields are on it. Document=data, form=presentation and logic, ok?

Overwriting the clipboard on document save is likely to make users unhappy, as they are likely to assume they can cut something from a document, save and exit, and paste it into another document. The way you’re doing it involves data loss in such a case. I suggest you either make do with the line break instead of paragraph break.

An alternative, since you are saving the document anyway, is to use the Querysave event to modify the rich text exclusively in the back end (you will have to use Source.Refresh(True) first), then in the postsave event, if they are not also closing the document, close and reopen the document using EditDocument. It may require some work to determine whether they are closing the document.

Subject: RE: LotusScript AddNewLine

"You can insert a line break into some rich text using, for instance:

Source.FieldAppendText “fieldname”, {

}"

That did the trick! Thanks for your help Andre.

As a point of interest I tried a very simple script to create a new Document and got the form not found error!

Subject: RE: LotusScript AddNewLine

I have written code to create a document in memory and open it on screen, many times. It works perfectly well, with no “Form not found” error, provided the form exists. You can’t just make up a form name and assign it to the form item (“Dummy Form”). You have to use a form you already have.

Subject: RE: LotusScript AddNewLine

Andre

Thanks for your patience - it just clicked!