LotusScript experts: What's wrong with this "send" code?

2nd posting as the other was difficult to follow.

I have a form called dlgSendIT which has the following code in the QuerySave event. I need to send an e-mail with the field contents of this form using either this form or a Memo form.

Please help! Nothing is working.

Sub Querysave(Source As Notesuidocument, Continue As Variant)

Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Set db = session.CurrentDatabase

Set doc = New NotesDocument( db )

doc.Form = “dlgSendIT”

doc.SendTo = doc.GetItemValue(“SendTo_1”)

Call doc.Send( False )

End Sub

Subject: LotusScript experts: What’s wrong with this “send” code?

Try to put the code in QueryClose

Subject: LotusScript experts: What’s wrong with this “send” code?

Angie,

There are a number of things to question:

o Using doc.Send(True) will ensure all fields in a doc are sent, because it sends the form also.

o You create a new back-end doc based on form dlgSendIT, but you don’t store any data, so there will be nothing to send unless everything has a default value. Also, if the SendTo_1 field lacks a default value, the e-mail will have nowhere to go.

o You haven’t linked the in-memory doc – the NotesUIDocument – to this new back-end doc you are creating, so what you are saying is that information you need to send has no connection to data filled in the on screen doc? That would be odd, but can be done.

Ken

Subject: LotusScript experts: What’s wrong with this “send” code?

I’m not sure why you’re creating a new document, nor do I see how this line can work:

doc.SendTo = doc.GetItemValue("SendTo_1")

The field “SendTo_1” hasn’t been created and / or populated, so doc.SendTo is going to be empty, no matter what.

Subject: RE: LotusScript experts: What’s wrong with this “send” code?

Okay, that explains why the e-mail isn’t sent but how do I fix it? I need the value in the SendTo_1 field.

Subject: RE: LotusScript experts: What’s wrong with this “send” code?

I know you need the value in SendTo_1 but where’s it supposed to come from? Per your code at the start of this thread, the only place is thin air.

You can’t get the value in that field until you’ve set it. If the document you’re invoking this code from contains this field, and that field in turn contains a value, then grab it and pass it to your code. But I think that the LS you provided at the start of this thread is the whole story, and so then SendTo_1 is empty. It needs to be instantiated. You may be relying on form / field formula to provide a value, but given that you create “doc” in the back-end, this formula won’t get triggered, so bear than in mind.

Subject: RE: LotusScript experts: What’s wrong with this “send” code?

I believe that Ben is on the right track with what is happening with my code. I’m not receiving error messages when running thru debugger. In fact, it doesn’t appear to trigger anything when run thru debugger.

I appreciate everyone’s help so much. I’ve never had any formal lotusscript training so am floundering with the basics. I’m trying to instantiate the SendTo_1 field with the code below.

It allows me to save the code but doesn’t work. What am I doing wrong now?

Sub Querysave(Source As Notesuidocument, Continue As Variant)

Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Set db = session.CurrentDatabase

Set doc = NotesDocument



doc.SendTo_1 = Source.FieldGetText("SentTo_1")



Call doc.Send( False) 

End Sub

Subject: RE: LotusScript experts: What’s wrong with this “send” code?

Unless you have already saved the document, how can you send it.

Try it in the post save, and also look at the code I posted earlier. SendTo_1 will not send to anyone. The field needs to be SendTo.

did you really mean:

Source.FieldGetText(“SentTo_1”)

or did you mean

Source.FieldGetText(“SendTo_1”)

Also, if you are truly sending the document, use

Call doc.Send( True)

so the form will be stored in the document.

All of these things are covered in the help file.

Subject: LotusScript experts: “Its not working!”

I’m sorry but I’m really becoming lost with all of the advice. I’m a relative newbie to LotusScript and haven’t needed to use it for more than a year.

I currently have the following code in my QuerySave event. What bothers me is why doesn’t this kickoff in debugger mode when I click OK on the dialog box? I can’t get it to save or show any information.

Sub Querysave(Source As Notesuidocument, Continue As Variant)

Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Set db = session.CurrentDatabase

Set doc = NotesDocument



Call doc.Save( False, False )

    doc.SendTo = Source.FieldGetText("SendTo1")

Call doc.Send( True)

End Sub

Subject: Well shoot…

to get the QuerySave to kick off in the debugger, turn the debugger on before editing or creating a document.

When the debugger opens for the first time, change the event to QuerySave, and doubleclick on the line

Set db = session.CurrentDatabase

this will put a stop in. Then click continue. That way when you do the save, the debugger will kick off.

Subject: RE: Well shoot…

No luck, I’ve done what you’ve suggested but it still stops debugging on the main form. Currently the dialog box is called from the PostSave event of the main form. I watch it go thru debugging of the main form, the dialog box pops up and the debugger stops and nothing happens with the save or send.

Thanks,

Angie

Subject: How do I put messageboxes in my code to see if my querysave is triggered?

Sub Querysave(Source As Notesuidocument, Continue As Variant) Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Set db = session.CurrentDatabase

Set doc = NotesDocument

Messagebox doc.SendTo_1   

Call doc.Save( False, False )

doc.SendTo = Source.FieldGetText("SendTo_1")



Call doc.Send( True)

End Sub

Subject: A little clarification maybe?

So you are trying to take the following steps:

  1. Compose (or edit a document)

  2. in the PostSave launch a dialog box to gather additional information. ← Is dialog box a new document or are you re-displaying the document from step 1?

  3. In the QuerySave of the DialogBox you want to send out this email.

If that scenario is correct you won’t be able to debug the QuerySave in your dialog box. If I’m not mistaken the debugger will not allow you to debug code called from a dialog box.

What kind of information are you gathering from your dialog box? Is it merely the name of the person to send this memo to? Additional information not contained in the main document that needs to be mailed only and not saved in the main doc?

In addition, in the code you’ve posted you have:

Set doc = NotesDocument

If you are trying to compose a new document for mailing purposes only it needs to read:

Set doc = New NotesDocument(db)

Unless you’ve somehow managed to declare a variable somewhere called “NotesDocument” then doc is going to be set to nothing. Alternatively you could do:

Set doc = Source.Document

This will get a handle to the backend document represented by your dialog box. Not sure if that’s the approach you want to take though.

That’s probably enough questions for now but am I on the right track with my assumptions?

Subject: RE: A little clarification maybe?

You’re basically on the right track. I have a main document which on PostSave composes a dialog box. Basically this dialog box very closely resembles a “memo” form. I’d like to be able to mail this form when the dialog OK button is clicked.

I’ve changed the code as you’ve suggested but nothing happens. :frowning: What is my code doing?

Sub Querysave(Source As Notesuidocument, Continue As Variant)

Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Set db = session.CurrentDatabase

Set doc = New NotesDocument(db)

Messagebox doc.SendTo_1   

Call doc.Save( False, False )

doc.SendTo = Source.FieldGetText("SendTo_1")



Call doc.Send( True)

End Sub

I’ve put the following msgbox prompt into the form but its not prompting me with any message. I’m not at all sure that anything is happening in the dialog box QuerySave event.

Dim db As NotesDatabase

Dim doc As NotesDocument

Set db = session.CurrentDatabase

Set doc = New NotesDocument(db)

tmp = Source.FieldGetText("SendTo_1")

If  tmp = " " Then

	Msgbox "No value"

End If

Call doc.Save( False, False )

doc.SendTo = Source.FieldGetText("SendTo_1")



Call doc.Send( True)

End Sub

Subject: RE: A little clarification maybe?

Angie, prompt for the name in the Query save and store the information in temporary hidden fields. Then run the send in the postsave event.

The code is also all over the place. I sent you the solution in the other thread. Just use it!:slight_smile:

Subject: File Save…

Hi File Save,I’m trying to understand what you’re telling me in your postings. I think I’m missing some of the basics in LotusScript.

I know that you are exactly right that I don’t have those field values since the document hasn’t been saved.

You were also correct with the SendTo field when I was using SendTo_1. I’ve tried to correct that using this code.

Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Set db = session.CurrentDatabase

Set doc = New NotesDocument(db)



doc.SendTo = Source.FieldGetText("SendTo_1") 

I have this code in my QuerySave event.

Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument



Set db = session.CurrentDatabase

Set doc = source.document 

Call doc.Save( True, True )

Since I can’t test this in debugger I’m unable to figure out how this is supposed to work. I’m not receiving any error messages. Please help. Can you make the corrections to my code and hopefully I can learn from that.

Subject: RE: File Save…

Angie,

you are making this way too hard.

In the QuerySave of the document (after all vailidations have passed), NOT the dialog box)

Sub Querysave(Source As Notesuidocument, Continue As Variant)

Dim session As New NotesSession

Dim db As NotesDatabase

Set db = session.CurrentDatabase

Dim docCurrent As NotesDocument

set docCurrent=source.document

Call doc.ReplaceItemValue( “SendTo”, doc.SendTo_1 )

call doc.save(false, true )

Call doc.Send( True )

End Sub

If you need to get a user selection of a name:

Sub Querysave(Source As Notesuidocument, Continue As Variant)

dim ws as New NotesUIWorkspace

Dim session As New NotesSession

Dim db As NotesDatabase

Set db = session.CurrentDatabase

Dim docCurrent As NotesDocument

set docCurrent=source.document

Dim picklist As Variant

'To allow multiple names:

picklist = ws.PickListStrings( PICKLIST_NAMES, True )

’ To allow only one name

picklist = ws.PickListStrings( PICKLIST_NAMES )

Call doc.ReplaceItemValue( “SendTo”, Picklist )

call doc.save(false, true )

Call doc.Send( True )

End Sub

Subject: RE: File Save…

Ahh,as the light goes on. Now my problem is that my lead developer created this dialog box form which he wants me to use. Its very much like a custom memo form.

In fact, I think you helped me out the other day with the code necessary to compose the dialog box only when the “Assignees” field had a change. You recommended a (hidden) radiobutton which works beautifully.

Now I either need to send this customized memo form via e-mail or copy the contents into a regular mail memo message. I just want to be sure that if I send the dialog box it has to display in the inbox view.

As always, your help and everyone else’s is GREATLY appreciated.

Subject: RE: File Save…

Tell him to get over himself:-)

You can still use the dialog box. Just put fields on the form that are the same as the dialog box.

then use

Call ws.DialogBox( “DirectReports”, True, True ) instead of the picklist and use the values stored in the fields on the document.

Subject: File Save… I’m almost there! :slight_smile:

Thanks File Save as your code is almost working for me.

Now what I’m seeing is that

#1. When it calls the dialog box its populated with whatever document was selected in the view. That’s not what was intended as this is a brand new document.

#2. The other issue is the dialog box has a body field which is editible allowing the user to add additional information. I want to bring the contents into the main form. How do I do this?

Sub Querysave(Source As Notesuidocument, Continue As Variant)

Dim ws As New NotesUIWorkspace

Dim session As New NotesSession

Dim db As NotesDatabase

Set db = session.CurrentDatabase

Dim docCurrent As NotesDocument

Set docCurrent=source.document





docCurrent.Form = "dlgSendIT" 



Call ws.DialogBox( "dlgSendIT", True, True ) 

Call docCurrent.save(False, True )

Call docCurrent.Send( True )

End Sub

Thanks,

Angie