LS: Creating a new document from within another document and saving/closing both

Hi Eveyone,

I am having problems with this LS code below. What I need it to do is the following:

A user displays a document in the db (notes client), then hits the Opt-Out button, this button should do the following in LS.

It needs to save and close (if it can) the existing document they are in (with the opt-out button), then open a new document using a different form. Then this new document is saved and closed and emailed.

I’d really appreciate some help, and thanks as usual in advance to everyone who might resond.

Here is my code:

Sub Click(Source As Button)

Dim ws As New NotesUIWorkspace

Dim db As NotesDatabase

Dim doc As NotesDocument

Dim uidoc As NotesUIDocument

Dim newdoc As NotesDocument

Dim emaildoc As NotesDocument

Dim emailbody As NotesRichTextItem



Set uidoc = ws.currentdocument

Set doc = uidoc.document

Set db = doc.ParentDatabase

Set newdoc = New NotesDocument(db)



Dim boxType As Long, answer As Integer

boxType& = 3+ 32

mtexttodisplay = "Continue to Submit Opt-Out Form"

Messagebox  "I have opted out of the company car scheme and accept company car allowance in lieu of a company vehicle.  I confirm that I am never required to drive on business.", boxType& , mtexttodisplay



uidoc.editMode = True



Call uidoc.FieldSetText("OptOutToggle", "No")

Call uidoc.FieldSetText("RetToggle", "No")

Call uidoc.FieldSetText("ResToggle", "Yes")

Call uidoc.FieldSetText("Status", "Retired")



Call uidoc.Save

Call uidoc.Close



newdoc.form = "OptOut"

newdoc.OnshoreOffshore = doc.OnshoreOffshore(0)

newdoc.AuthorisedName = doc.AuthorisedName(0)

Call newdoc.FieldSetText("AppToggle", "Yes")

Call newdoc.FieldSetText("RejToggle", "Yes")

Call newdoc.FieldSetText("Status", "Pending Approval")

Call newdoc.FieldSetText("NewDoc", "No")



Set newuidoc = ws.EditDocument(True, newdoc)



Set emaildoc=New NotesDocument(db)

Set emailbody =New NotesRichTextItem(emaildoc,"Body")

emaildoc.Form = "Memo"

emaildoc.Subject = "Business Drivers DB - Opt-Out Approval is required for  " & uidoc.FieldGetText("Name")

emaildoc.SendTo=newdoc.AuthorisedName

emaildoc.CopyTo=newdoc.Facilities



Call emailbody.AddNewLine(2)

Call emailbody.AppendText("This Opt-Out form for " & uidoc.FieldGetText("Name") & " has been sent to you to approve.")

Call emailbody.AddNewLine(2)

Call emailbody.AppendText("Please follow the link below, Thank You...")

Call emailbody.AddNewLine(2)

Call emailbody.AppendText("Link to task -->>")

Call emailbody.AppendDocLink(newdoc,db.Title)

flag=emaildoc.ComputeWithForm(False,False)

Call emaildoc.Send(False)

Call newdoc.Save( False, False )

Call newdoc.close

End Sub

I am getting a Illegal use of PROPERTY box on the line:

Call newdoc.FieldSetText(“AppToggle”, “Yes”)

Before I added setting the fields on the new document and the email section, it was working but did not close the original document with the button, but it was working as in the new form was displayed and saved etc…

Thanks again.

Hayley.

Subject: LS: Creating a new document from within another document and saving/closing both

newdoc is a notesdocument so you can not use FieldSetText which is for a notesuidocument.

Use

newdoc.AppToggle = “Yes”

At the end of the script you are closing newdoc but newuidoc is the open document. You could also try putting uidoc.Close as the last line to see if this closes the original document.

Subject: LS: Creating a new document from within another document and saving/closing both

A couple of other things I have noticed.

You are not testing whether the user presses Yes No or cancel on the messagebox so the code will continue regardless of what option they select. You need to add

answer = Messagebox (“I have opted out of the company car scheme and accept company car allowance in lieu of a company vehicle. I confirm that I am never required to drive on business.”, boxType& , mtexttodisplay)

'check for Cancel or no

If answer = 2 Or answer = 7 then

'do something

else

'do something else

end if

Also is there any reason why you are opening the new document on the front end using Set newuidoc = ws.EditDocument(True, newdoc) when you are trying to close it at the end of the script. A document can be created on the back end using the notesdocument class.

Subject: RE: LS: Creating a new document from within another document and saving/closing both

Hi Matt,

Thanks for your input. I have managed to fix this now.

Because I’ve managed to go into edit mode in the new document and close the original document, I don’t need the messagebox. But thank you for pointing that out, I’ll certainly remember that. Here is my code now and it appears to be working great:

Dim ws As New NotesUIWorkspace

Dim db As NotesDatabase

Dim doc As NotesDocument

Dim uidoc As NotesUIDocument

Dim newdoc As NotesDocument

Dim emaildoc As NotesDocument

Dim emailbody As NotesRichTextItem

Dim newuidoc As NotesUIDocument



Set uidoc = ws.currentdocument

Set doc = uidoc.document

Set db = doc.ParentDatabase

Set newdoc = New NotesDocument(db)



uidoc.editMode = True



Call uidoc.FieldSetText("OptOutToggle", "No")

Call uidoc.FieldSetText("RetToggle", "No")

Call uidoc.FieldSetText("ResToggle", "Yes")

Call uidoc.FieldSetText("Status", "Retired")



Call uidoc.Save

Call uidoc.Close



newdoc.form = "OptOut"

newdoc.OnshoreOffshore = doc.OnshoreOffshore(0)

newdoc.AuthorisedName = doc.AuthorisedName(0)

newdoc.AppToggle = "Yes"

newdoc.RejToggle = "Yes"

newdoc.Status = "Draft"

newdoc.NewDoc= "Yes"



Set newuidoc = ws.EditDocument(True, newdoc)