Adding a comment to a email and a field

I have a table on my form - it has 20 rows.  The top row has no fields but has a action button.  The rest of the rows have a editable text field on each row.  Here is what I want, if it can be done?

when the user hits the action button - a form/dialog box appears - with a sendto field and comment field.  The user selects who he wants to send the email to and then adds their comments - the user hits send and the email is sent with the comment to the selected user.  Then the comment is added to the 20 rows table on the form.  So the comment is saved on the form.  

If this makes no sense I can try to it again.

Jaziar
JaziarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

qwaleteeCommented:
Can be done... realizing the 20 limit
0
qwaleteeCommented:
Note: Much easier in script than formula
0
p_parthaCommented:
Jaziar,
"when the user hits the action button - a form/dialog box appears - with a sendto field and comment field." - so the user enters comments, but how do u want it to be split across the 20 editable text fields...

Partha
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

qwaleteeCommented:
REM Let's assume at this point you have already gotten the input, and sent off the e-Mail.
REM The comment text is in a variable named COMMENT.
REM The message recipient is in a variable named RECIPIENT.
REM The table has four columns.
REM Except for the first row, the first column contains fields CmntDate_1, CmntDate_2, ... , CmntDate_20
REM Second column contains fields CmntFrom_1, ..., CmntFrom_20
REM Third column contains fields CmntTo_1, ... , CmntTo_20
REM Fourth column contains Cmnttext_1 , ..., CmntText_20

Dim s as new NotesSession
Dim ws as New NotesUiWorkspace
Dim uiDoc as notesUiDocument
Set uiDoc = ws.currentDocument
Dim doc as notesDocument
Set doc = uiDoc.Document
Dim i as integer
For i = 1 to 20
  If doc.getItemValue("CmntFrom_" & i)(0) = "" Then
    doc.replaceItemValue "CmntFrom_" & i , s.userName
    doc.replaceItemValue "CmntText_" & i , COMMENT
    doc.replaceItemValue "CmntTo_" & i , RECIPIENT
    doc.replaceItemValue "CmntDate_" & i , Now
  ElseIf i = 20 Then
    MsgBox "Your comment was sent, but it could not be recorded here because the table was full."
  End If
Next
0
qwaleteeCommented:
The fields on the table should all be computed when composed, with a null string formula ("")
0
HemanthaKumarCommented:
You can transfer the values using this script.

THis is a prototype, let me know if you don't get it

Sub Click(Source As Button)
      Dim session As New NotesSession
      Dim doc As NotesDocument, dialog As NotesDocument
      Dim ws As New NotesUIWorkspace
' Call the dialog.
      Set db = session.CUrrentDatabase
      Set dialog = db.CreateDocument
      flag = ws.DialogBox( "DialogForm", 1,1, 0, 1, 1, 0, "title", dialog)
' Transfer the values to the fields.
      Set doc = ws.CurrentDocument.Document
      For i = 1 To 20            
            s = doc.GetItemValue( "SendTo_" & i )
            If s = "" Then
                  Call doc.ReplaceItemValue( "SendTo_" & i , dialog.SendTo)
                  Call doc.ReplaceItemValue( "Comments_" & i , dialog.Comments)
                  Exit Sub
            End If            
      Next i
End Sub

~Hemanth
0
HemanthaKumarCommented:
I forgot to include the cancel action , here is the corrected code

Sub Click(Source As Button)
      Dim session As New NotesSession
      Dim doc As NotesDocument, dialog As NotesDocument
      Dim ws As New NotesUIWorkspace
' Call the dialog.
      Set db = session.CUrrentDatabase
      Set dialog = db.CreateDocument
      flag = ws.DialogBox( "DialogForm", 1,1, 0, 1, 1, 0, "title", dialog)
' Transfer the values to the fields.
      If flag Then
            Set doc = ws.CurrentDocument.Document
            For i = 1 To 20            
                  s = doc.GetItemValue( "SendTo_" & i )
                  If s = "" Then
                        Call doc.ReplaceItemValue( "SendTo_" & i , dialog.SendTo)
                        Call doc.ReplaceItemValue( "Comments_" & i , dialog.Comments)
                        Exit Sub
                  End If            
            Next i
      End If
End Sub
0
qwaleteeCommented:
Hemantha's script looks almost exactly like my script! :)

He adds some code for getting the values (which I did not), but I have a place to record the sender and recipient (which he does not).  Neither of us bothered with the mail sending, which is not difficult:

Dim s as new notesSession
Dim db as notesDatabase
Set db = s.currentdatabase
Dim message as notesDocument
Set message = db.createDocument
message.Form = "Memo"
message.Subject = "Comment from database " & db.Title
message.Body = COMMENT
message.SendTo = RECIPIENT
message.Send false
0
JaziarAuthor Commented:
Not to mess things up but would it be easier and cleaner to append all the comments in one field verses having the 20 rows?
0
qwaleteeCommented:
It would be sortof cleaner, but you would have a UI problem, if you wanted to line up names with their comments.  The comments would wrap, taking up multiple lines, and you would have no way to keep the matching names/dates in line with their comments.

Another way to do this would be to have one bug mega field containing names, dates, and comments, which you would then have trouble parsing out later iof you ever wanted to.  Something like this:

Set history = doc.getFirstItem("CommentHistory")
history.AppendToTextItem Now & " From " & RECIPIENT & " To " & s.userName & Chr$(13)
history.AppendToTextItem "------------------------------------------------------" & Chr$(13)
history.AppendToTextItem COMMENT & Chr$(13)
history.AppendToTextItem "======================================================" & Chr$(13)




    doc.replaceItemValue "CmntText_" & i , COMMENT
    doc.replaceItemValue "CmntTo_" & i , RECIPIENT
    doc.replaceItemValue "CmntDate_" & i , Now
0
qwaleteeCommented:
Oops, drop the last thre lines, left over from previous comment
0
qwaleteeCommented:
Another oops, not AppendTotextItem, but AppendToTextList
0
JaziarAuthor Commented:
Qwaletee would that code go in to the action button or would it be the value for the text field.  What interface am I using to get the email address and comment  - does it pop up a form or a prompt?  I am little lost
0
JaziarAuthor Commented:
I created a form named Desc
sendto = DescSendTo
comment = DiscComment
I put a button on there that does this

Mail := @Trim(DiscSendTo);
subject := "Testing Email";
message := @NewLine + @NewLine + DiscComment + @NewLine + @NewLine + "Testing";
@MailSend(Mail; ""; "";subject; ""; message + @NewLine+@NewLine);
@Command([FileCloseWindow])

So that sends the comment to the address - works fine - Now I need to figure out to add this piece with that you guys have up there.  I would like just to append the comment - username - date to the same field.  I think we are getting there.
0
HemanthaKumarCommented:
Convert the above to lotus script and place it in queryclose of the dialog box form. Use DialogBoxCanceled property to see if the user pressed OK or Cancel button and appropriately execute the script.

In QueryClose use this script equivalent of the above formula

if not source.DialogBoxCanceled then
Dim s as New NotesSession
dim db as NotesDatabase
dim doc as NotesDocument, note as notesdocument
set db = s.CurrentDatabase
set note = source.Document
set doc = db.CreateDocument

doc.SendTo = note.DescSendTo
doc.Subject = "Testing mail"
set rtitem = doct.CreateRichTextItem( "Body" )
call rtitem.AppendText( CHR$(13) + CHR$(13) + note.DiscComment(0) + CHR$(13) + CHR$(13) + "Testing");
doc.send false
End if

0
HemanthaKumarCommented:
include doc.Form = "Memo" in the above script
0
qwaleteeCommented:
Use some of Hemanth's ealier code (his first comment) to pop up the dailog box -- you will have to create a subform that has the dialog layout, and use that subform name in the ws.DialogBox.  The values are returned in fields in the "dialog" document (Hemanth actually names the variable "dialog").

All this goes in your "add comment" or "send comment" button.

So, we end up with:
     Dim session As New NotesSession
     Dim doc As NotesDocument, dialog As NotesDocument
     Dim ws As New NotesUIWorkspace
' Call the dialog.
     Set db = session.CUrrentDatabase
     Set dialog = db.CreateDocument
     flag = ws.DialogBox( "DialogForm", 1,1, 0, 1, 1, 0, "title", dialog)
     If not flag Then Exit Sub

Dim comment as string, recipient as string
comment = dialog.comment(0)
recipient = dialog.recipient(0)

Dim message as notesDocument
Set message = db.createDocument
message.Form = "Memo"
message.Subject = "Comment from database " & db.Title
message.Body = COMMENT
message.SendTo = RECIPIENT
message.Send false

set doc = ws.currentDocument.document
Set history = doc.getFirstItem("CommentHistory")
history.AppendToTextList Now & " From " & RECIPIENT & " To " & s.userName & Chr$(13)
history.AppendToTextList "------------------------------------------------------" & Chr$(13)
history.AppendToTextList COMMENT & Chr$(13)
history.AppendToTextList "======================================================" & Chr$(13)
doc.save true,true

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bozzie4IT ArchitectCommented:
Are you using R6 ?  If you use R6 you can create a dynamic table, that will grow however large you want.  You can also use passtru html in r6 to build the table from several multi-value fields (enable show passtru html in Notes).

Another approach to create a similar effect would be to create separate documents for your comments, as responses.  Now create a view, with a categorized first column, @text($Ref).
Put in the next columns the fields you like to show, and sort them how you would like.
Now include that view as embedded view, show single category in your form.

Now you have a dynamically growing comments list.  In R6, you can go 1 step further, and use the new InviewEdit feature, to allow people to fill in the form tru the embedded view.

To create the responses, simple use (if newResponse is a response document)
@command([compose]; "newResponse" )

cheers,

Tom

0
Bozzie4IT ArchitectCommented:
And in the QuerySave for newResponse, add the @mailsend function or the LS to send the mail.  
Not: This will not be the best way when you are using the InViewEdit feature.

cheers,

Tom
0
JaziarAuthor Commented:
Set history = doc.getFirstItem("CommentHistory")
 
Is this getting the field on the main form that I want to display to?  So it is getting the value of CommentHistory(which on my form is comments) and appending the new info?

comment = dialog.comment(0)
recipient = dialog.recipient(0)

Is this is getting the values from the dialog form?  

Dim message as notesDocument
Set message = db.createDocument
message.Form = "Memo"
message.Subject = "Comment from database " & db.Title
message.Body = COMMENT
message.SendTo = RECIPIENT
message.Send false

What exactly is this doing?  Is it setting up a email?  

When I run what you have in the action button - my form comes up and I can add the email address and comment - on that form I have a send email button - I click it and the email is sent and the form is closed.  I am now sitting back at my master form.  But no Info has been added to the comment section.  
0
JaziarAuthor Commented:
OK I have removed the send email button from the subform.  I see the code above sends a email.  Now all I need to know is how to get the variable from the form and update it with the dialog values?  I am sure it is in front of my face, but I am missing it.
0
JaziarAuthor Commented:
Set doc = ws.currentDocument.document
      Set history = doc.getFirstItem("Discussion")
      history.AppendToTextList Now & " From " & RECIPIENT & " To " & s.userName & Chr$(13)
      history.AppendToTextList "------------------------------------------------------" & Chr$(13)
      history.AppendToTextList COMMENT & Chr$(13)
      history.AppendToTextList "======================================================" & Chr$(13)
      doc.save True,True
End Sub

Set history = doc.getFirstItem("Discussion") <- Discussion is the name of the text field (Computed) I want to append all the text to.

When I hit ok on the subform I get the following error, but I still get the email

Variant does not contain an object


0
Bozzie4IT ArchitectCommented:
Yes that won't work if you have a new document.

If you want the script to work, Discussion must be a Computed when composed text field, or Computed with formula : Discussion

..
set history = doc.getfirstitem( "Discussion" )
if history is nothing then
set history = doc.replaceitemvalue( "Discussion" , Now & " From " & RECIPIENT & " To " & s.userName & Chr$(13) )
else
history.AppendToTextList Now & " From " & RECIPIENT & " To " & s.userName & Chr$(13)
end if
 history.AppendToTextList "------------------------------------------------------" & Chr$(13)
     history.AppendToTextList COMMENT & Chr$(13)
     history.AppendToTextList "======================================================" & Chr$(13)
 doc.save True,True
...

Are you using R5 or R6 ?

cheers,

Tom
0
JaziarAuthor Commented:
R5
0
JaziarAuthor Commented:
I get the same error - does the form need to be refreshed to see the changes?
0
JaziarAuthor Commented:
My Problem Is Diffently in

      Set doc = ws.currentDocument.document
      Set history = doc.getfirstitem( "Discussion" )
      If history Is Nothing Then
            Set history = doc.replaceitemvalue( "Discussion" , Now & " From " & RECIPIENT & " To " & s.userName & Chr$(13) )
      Else
            history.AppendToTextList Now & " From " & RECIPIENT & " To " & s.userName & Chr$(13)
      End If
      history.AppendToTextList "------------------------------------------------------" & Chr$(13)
      history.AppendToTextList COMMENT & Chr$(13)
      history.AppendToTextList "======================================================" & Chr$(13)
      doc.save True,True


It seems to me and I dont fully understand the error that doc.getfirstitem( "Discussion" ) is not working correctly.  Could it be trying to get Discussion off the subform? instead of the main form?  Just a question
0
HemanthaKumarCommented:
Where is this discussion item located. Main form or Dialog ? And what is the error ?
0
JaziarAuthor Commented:
Discussion is in the main form - Discussion is the field I want to append all the text comments to

The error is

Variant does not contain an object
0
Bozzie4IT ArchitectCommented:
It doesn't really matter where the discussion item is.

I would change the script (again) though,  because now, it does changes in the backend that are not reflected immediately in the front end.

'Set doc = ws.currentDocument.document  <--- remove this line
set uidoc = ws.currentDocument
     Set history = uidoc.document.getfirstitem( "Discussion" )
     If history Is Nothing Then
          Set history = uidoc.document.replaceitemvalue( "Discussion" , Now & " From " & RECIPIENT & " To " & s.userName & Chr$(13) )
     Else
          history.AppendToTextList Now & " From " & RECIPIENT & " To " & s.userName & Chr$(13)
     End If
     history.AppendToTextList "------------------------------------------------------" & Chr$(13)
     history.AppendToTextList COMMENT & Chr$(13)
     history.AppendToTextList "======================================================" & Chr$(13)
     
' save it in the backend, but update changes
call uidoc.document.save(True,True)
Call uidoc.reload()

Tom
0
Bozzie4IT ArchitectCommented:
in the options section of you button, put

Option Declare

That will help you find potential problems....

cheers,

Tom
0
JaziarAuthor Commented:
1. Set db = session.CUrrentDatabase => RED

2. flag = ws.DialogBox( "Disc", 1,1, 0, 1, 1, 0, "title", dialog) => RED w/error Variable not declared: flag

3. Set uidoc = ws.currentDocument => RED w/error Variable not declared: uidoc

4. Set history = uidoc.document.getfirstitem( "Discussion" ) => RED w/error Variable not declared: history

5. Set history = uidoc.document.replaceitemvalue( "Discussion" , Now & " From " & RECIPIENT & " To " & s.userName & Chr$(13) ) => did not show up in RED but has a error of Variable not declared : S

I think I am so close!

0
JaziarAuthor Commented:
Should I  do a DIM history As String -> that will declare the field

After I do that I am down to one error and that is in this line

Dim Discussion As String, history As String
      Set history = uidoc.document.getfirstitem( "Discussion" )
      If history Is Nothing Then
            Set history = uidoc.document.replaceitemvalue( "Discussion" , Now & " From " & RECIPIENT & " To " & s.userName & Chr$(13) )
      Else

=>=>=>**history.AppendToTextList Now & " From " & RECIPIENT & " To " & s.userName & Chr$(13) <= ERROR Not A Instance Name: History
      
                End If
      history.AppendToTextList "------------------------------------------------------" & Chr$(13)
      history.AppendToTextList COMMENT & Chr$(13)
      history.AppendToTextList "======================================================" & Chr$(13)
0
JaziarAuthor Commented:
Here is my Complete Code I have right now---- See Below

Sub Click(Source As Button)
      Dim session As New NotesSession
      Dim uiDoc As notesUiDocument
      
      Dim doc As NotesDocument, dialog As NotesDocument
      Dim ws As New NotesUIWorkspace
      Dim s As New NotesSession
      Dim db As NotesDatabase
      Set db = session.CUrrentDatabase
      Set dialog = db.CreateDocument
      Set uiDoc = ws.currentDocument      
      Dim flag As String      
      flag = ws.DialogBox( "Disc", 1,1, 0, 1, 1, 0, "title", dialog)
      If Not flag Then Exit Sub
      
      Dim comment As String, recipient As String
      comment = dialog.DiscComment(0)
      recipient = dialog.DiscSendTo(0)
      
      Dim message As notesDocument
      Set message = db.createDocument
      message.Form = "Memo"
      message.Subject = "Discussion Thread from database " & db.Title
      message.Body = COMMENT
      message.SendTo = RECIPIENT
      message.Send False
      
      Set uidoc = ws.currentDocument
      Dim Discussion As String, history As String
      Set history = uidoc.document.getfirstitem( "Discussion" )
      If history Is Nothing Then
            Set history = uidoc.document.replaceitemvalue( "Discussion" , Now & " From " & RECIPIENT & " To " & s.userName & Chr$(13) )
      Else
            history.AppendToTextList Now & " From " & RECIPIENT & " To " & s.userName & Chr$(13)
      End If
      history.AppendToTextList "------------------------------------------------------" & Chr$(13)
      history.AppendToTextList COMMENT & Chr$(13)
      history.AppendToTextList "======================================================" & Chr$(13)
      
' save it in the backend, but update changes
      Call uidoc.document.save(True,True)
      Call uidoc.reload()
      
End Sub
0
HemanthaKumarCommented:
Declare history as item, like this

Dim history as NotesItem
0
JaziarAuthor Commented:
I made that change and now I am getting a type mismatch
0
JaziarAuthor Commented:
OK I have resolved the problems - YaaHoo  

There are 2 issues left

1.  When I put more than one email in the sendto - it only emails the first name?
2.  The username is full cn=bob socks etc - I would like it in @Name([CN]; @username)?

0
p_parthaCommented:
Jaziar,
change it to liek this

Dim session As New NotesSession
    Dim uiDoc As notesUiDocument
   
     Dim doc As NotesDocument, dialog As NotesDocument
    Dim ws As New NotesUIWorkspace
    Dim s As New NotesSession
    Dim db As NotesDatabase
    Set db = session.CUrrentDatabase
    Set dialog = db.CreateDocument
    Set uiDoc = ws.currentDocument    
     Dim flag As String    
     flag = ws.DialogBox( "Disc", 1,1, 0, 1, 1, 0, "title", dialog)
    If Not flag Then Exit Sub
   
     Dim comment As String, recipient As String
    comment = dialog.DiscComment(0)
    recipient = dialog.DiscSendTo
     Dim message As notesDocument
    Set message = db.createDocument
    message.Form = "Memo"
    message.Subject = "Discussion Thread from database " & db.Title
    message.Body = COMMENT
    message.SendTo = RECIPIENT
    message.Send False
   
     Set uidoc = ws.currentDocument
    Dim Discussion As String, history As String
    Set history = uidoc.document.getfirstitem( "Discussion" )
    If history Is Nothing Then
         Set history = uidoc.document.replaceitemvalue( "Discussion" , Now & " From " & RECIPIENT & " To " & s.commonuserName & Chr$(13) )
    Else
         history.AppendToTextList Now & " From " & RECIPIENT & " To " & s.userName & Chr$(13)
    End If
    history.AppendToTextList "------------------------------------------------------" & Chr$(13)
    history.AppendToTextList COMMENT & Chr$(13)
    history.AppendToTextList "======================================================" & Chr$(13)
   
' save it in the backend, but update changes
    Call uidoc.document.save(True,True)
    Call uidoc.reload()
   
Partha
0
p_parthaCommented:
oops one change...

Dim session As New NotesSession
    Dim uiDoc As notesUiDocument
   
     Dim doc As NotesDocument, dialog As NotesDocument
    Dim ws As New NotesUIWorkspace
    Dim s As New NotesSession
    Dim db As NotesDatabase
    Set db = session.CUrrentDatabase
    Set dialog = db.CreateDocument
    Set uiDoc = ws.currentDocument    
     Dim flag As String    
     flag = ws.DialogBox( "Disc", 1,1, 0, 1, 1, 0, "title", dialog)
    If Not flag Then Exit Sub
   
     Dim comment As String, recipient As String
    comment = dialog.DiscComment(0)
    recipient = dialog.DiscSendTo(0)
     Dim message As notesDocument
    Set message = db.createDocument
    message.Form = "Memo"
    message.Subject = "Discussion Thread from database " & db.Title
    message.Body = COMMENT
    message.SendTo = dialog.DiscSendTo
    message.Send False
   
     Set uidoc = ws.currentDocument
    Dim Discussion As String, history As String
    Set history = uidoc.document.getfirstitem( "Discussion" )
    If history Is Nothing Then
         Set history = uidoc.document.replaceitemvalue( "Discussion" , Now & " From " & RECIPIENT & " To " & s.commonuserName & Chr$(13) )
    Else
         history.AppendToTextList Now & " From " & RECIPIENT & " To " & s.commonuserName & Chr$(13)
    End If
    history.AppendToTextList "------------------------------------------------------" & Chr$(13)
    history.AppendToTextList COMMENT & Chr$(13)
    history.AppendToTextList "======================================================" & Chr$(13)
   
' save it in the backend, but update changes
    Call uidoc.document.save(True,True)
    Call uidoc.reload()
   
Partha
0
JaziarAuthor Commented:
OK I know this is getting old - but I will make it worth the time

When the field is empty it works fine, but when there is already some data in the field I get this error when I click the button

Document Command Is Not avaiable
0
Bozzie4IT ArchitectCommented:
Where do you get this error exactly ?
Try to enable the debugger - and step tru your code untill you get the error.

cheers,

Tom
0
qwaleteeCommented:
And I'm guessing you still don't have multiple recipients working. To make that work, in your dialog box form or subfrm, set the field to be multiple valued.  Declare RECIPIENT as variant (Dim RECIPIENT As Variant).  This will allow the memo's SendTo to accept whatever single or multiple values are entered in the dialog.

As to the Document Command Is Not avaiable, as Tom says, use debugger.  There is a debuger bug when using form buttons; put the statement STOP at the top of your script to avoid it.
0
JaziarAuthor Commented:
OK that fixed the multiple email problem - IT now sends emails to all the names.  How do I turn the dugger on?
0
Bozzie4IT ArchitectCommented:
File/Tools/Debug Lotusscript

cheers,

Tom
0
JaziarAuthor Commented:
It WOrks - IT WORKS - YEA!!!!!!!!!!  One last question ->  Can I put a link to the document in the email it sends
0
Bozzie4IT ArchitectCommented:
Yes, but you'll need to change the script a bit
instead of
message.Body = COMMENT

put
dim rtitem as notesrichtextitem
set rtitem = message.createrichtextitem( "Body" )

Call rtitem.AppendDocLink( uidoc.document , "link to document" )
Call rtitem.AddNewLine(2)
Call rtitem.AppendText( COMMENT )
...

cheers,

Tom
0
JaziarAuthor Commented:
I am going to create a new question so I can reward more points to people.  There is still a error and I will open the other question with it.  So look for the new post.
0
Bozzie4IT ArchitectCommented:
Well the problem is most likely there because you use the QueryClose event to do some uidoc stuff... Right ?

It should be possible to move the code away from the dialogbox , and put that in the main button.

cheers,

Tom

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.