Help With A Forward Action

I have a foward action button on my main form.  When someone gets a doclink from the main form and they come to the document they have a option of fowarding to a new user.

In the script it ask who do we want to send it to and then ask for a comment.

Say Jaziar opens the document and I want Bob to respond to the request - I click foward and it ask who - I put in Bob's name then it ask why - I type "Bob can you look at this and reply"  two things should happen here

1.  Bob should get a email with my comments and a doclink

"Jaziar has foward this to you and here are his comments" (something like this as a message)

2.  At the bottom of the Orig. Document it should append in a rich text Comments field
it should append -

Jaziar has fowarded the request to Bob
FW: Comments: Bob can you look at this and reply

This code I have was working when I was using 3 forms - now I am only using the main form - so there is a lot of code in this I dont think I need.  It stills emails and comments - but does not place anything in the document. This one line is causing a ID error -> Set pDoc = db.GetDocumentByUNID(thisDoc.SourceDocument(0))

Please help me clean up the code.

Sub Click(Source As Button)
      Dim ws As New NotesUIWorkspace
      Dim db As NotesDatabase
      Dim uiDoc As NotesUIDocument
      Dim thisDoc As NotesDocument
      Dim newDoc As NotesDocument
      Dim varNewTo As Variant
      Dim item As NotesItem
      Dim session As New NotesSession
      Dim view As NotesView
      Dim pDoc As NotesDocument
      Dim strServer As String
      Dim strFilename As String
      Dim rtItem As NotesRichTextItem
      Dim strToName As String
      Set uiDoc = ws.CurrentDocument
      Set thisDoc = uiDoc.Document
      Set db = thisDoc.ParentDatabase
      Set newDoc = New NotesDocument(db)
      Call thisDoc.CopyAllItems(newDoc, True)
      varNewTo = ws.PickListStrings(PICKLIST_NAMES, True)
      Set item= newDoc.GetFirstItem("DocReaders")
      Call item.AppendToTextList(varNewTo)
      item.isreaders = True
      k = Inputbox("Enter your comments")      
      Set item = newDoc.GetFirstItem("SendTo")
      item.Values = varNewTo
     'newDoc.SenderList = "Forwarded by " & session.CommonUserName & Chr$(13) & newDoc.SenderList(0)
      newDoc.Subject = "Fw: " & thisDoc.Subject(0)    
      newDoc.FowardComments = k      
      Call newDoc.Send(True)
' Now, put a note in the original database indicating that the document was forwarded.
      strServer = thisDoc.DatabaseServer(0)
      strFilename = thisDoc.DatabaseName(0)
      Set db = New NotesDatabase(strServer, strFilename)
      Set view = db.GetView("All Documents")
      Set pDoc = db.GetDocumentByUNID(thisDoc.SourceDocument(0))
      Set rtItem = thisDoc.GetFirstItem("Comments")
      strToName = StringReplace(item.Text, "CN=", "")
      strToName = StringReplace(strToName, "/OU=Lex/O=Lexmark", "")
      Call rtItem.AppendText("Forwarded to " & strToName & " by " & session.CommonUserName)
      Call rtItem.AddNewLine(1)
      Call rtitem.appendtext("Forwarded Comment:  " & k)
      Call rtItem.AddNewLine(1)
      Call pDoc.Save(True, False)
      Call uiDoc.Close(True)
End Sub
Who is Participating?
gavanhortonConnect With a Mentor Commented:
Is there any reason you need to use Script ?, If not try doing it with a formula...

1. Create a dialog form with a field called msgtext. Call the form [messagetext].

2. Replace your script action with the following formula
FIELD msgtext:="";
FIELD sendto:=@PickList([Name]);
@DialogBox("[messagetext]";[AutoVertFit]:[AutoHorzFit];"Message Text");
@MailSend(sendto;null;null;"Forwarded by " + @Name([CN];@V3UserName) + " at " + @Text(@Today) + " " + @Text(@Time(@Now)) ;msgtext;" Please Review the following --->";[IncludeDoclink])

If you need to add a comment to a rich text field then you will have problems with formulas. Normally I have a rich text field and then a standard text field called DocumentHistory in each document.

You can update your history with
FIELD DocumentHistory := DocumentHistory + @Char(13) + "Forwarded by " + @Name([CN];@V3UserName) + " at " + @Text(@Today) + " " + @Text(@Time(@Now))
I would try replacing the problem line with the following...

Set pDoc = db.GetDocumentByUNID(thisDoc.UniversalID)
JaziarAuthor Commented:
Yes that fixed that problem but the foward is still sending the form and not a memo form.  So when I try to open up the email I get

Illegal Circluar USE: Discussion Routines

Then it opens the form

I just want it to send a doc link back to the form
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

JaziarAuthor Commented:
I am trying the formula - but this part is really important

At the bottom of the Orig. Document it should append in a rich text Comments field
it should append -

Jaziar has fowarded the request to Bob
FW: Comments: Bob can you look at this and reply

It is a rich text field named Comments
JaziarAuthor Commented:
You are correct everything worked well except the appending of the text to the document.  Any suggestions on how to write to a rich text field?

There is no way to write to a rich text field using a formula. What you could do instead is have a hidden text field somewhere in your document. Write to the text field using a formula and then when you save or close the document you can use "Call notesRichTextItem.AppendText( text$ )" to update your rich text item with the comments.

It's not very elegant, but it should get the job done. Otherwise you will need to use Lotus Script.
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.

All Courses

From novice to tech pro — start learning today.