Lotus Script to send e-mail and link

reachkacy
reachkacy used Ask the Experts™
on
Hi,
I've a agent lotus script currently which creates documents reading a text file.  Now I've to take the 'Ticketnumber' from that lotusscript and at the end of that lotus script I've to put in more script which will e-mail the Ticketnumber to a person and cc 2 people.
send to is 1 member
and cc is 2 members.
Also I've to include the link of the document.


The one I'm using is this one currently. This one sends two different e-mails to two people. I want to send one e-mail to the main person and cc the other people.

                  Dim NewDoc As NotesDocument
                  Dim rtitem As NotesRichTextItem                                    
                  Set NewDoc = New NotesDocument( db )
                  Set rtitem = newDoc.CreateRichTextItem( "Body" )
                  NewDoc.SendTo = tdoc.Assignee                  
                  NewDoc.Subject = "New Ticket (" & TicketNum & ") has been Assigned to you"
                  Call rtitem.AppendText("A new Ticket (" & TicketNum & ") has been opened and you are the_
                                                                                        Primary  Person Assigned to it.")
                  Call rtitem.AddNewLine(1)
                  Call rtitem.AppendDocLink(Doc, "Document Link")
                  Call newDoc.Send(False)
                  
                  Dim NewDoc1 As NotesDocument
                  Dim rtitem1 As NotesRichTextItem                                    
                  Set NewDoc1 = New NotesDocument( db )
                  Set rtitem1 = newDoc1.CreateRichTextItem( "Body" )                  
                  NewDoc1.SendTo = tdoc.Assignee_1                  
                  NewDoc1.Subject = "New Ticket (" & TicketNum & ") has been Assigned to you"
                  Call rtitem1.AppendText("A new Ticket (" & TicketNum & ") has been opened_
                                                                                          and you are the Secondary Person Assigned to it.")
                  Call rtitem1.AddNewLine(1)
                  Call rtitem1.AppendDocLink(Doc, "Document Link")
                  Call newDoc1.Send(False)


I want to send it to tdoc.Assignee and cc it to tdoc.Assignee_1 and also I want to include the link. Currently the link is not going in the e-mail to them.

help!!!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
try this

Dim NewDoc As NotesDocument
              Dim rtitem As NotesRichTextItem                              
              Set NewDoc = New NotesDocument( db )
              Set rtitem = newDoc.CreateRichTextItem( "Body" )
              NewDoc.SendTo = tdoc.Assignee  
newdoc.copyto = tdoc.Assignee_1            
               NewDoc.Subject = "New Ticket (" & TicketNum & ") has been Assigned to you"
              Call rtitem.AppendText("A new Ticket (" & TicketNum & ") has been opened and you are the_
                                                                                       Primary  Person Assigned to it.")
              Call rtitem.AddNewLine(1)
              Call rtitem.AppendDocLink(NewDoc, "Document Link")
              Call newDoc.Send(False)


HTH
partha

P.S: Doc was not at all declared but was used

Commented:
Where you have
               NewDoc1.SendTo = tdoc.Assignee_1
               Set rtitem1 = newDoc1.CreateRichTextItem( "Body" )

Do the following.  Let's say we have variables named sendToName, ccName1, and ccName2.  Here is your code:


               NewDoc1.SendTo = tdoc.Assignee_1

               Dim ccNameArray(0 to 1) as string
               ccNameArray(0) = ccName1
               ccNameArray(1) = ccName2
               NewDoc1.CopyTo = ccNameArray 'assign full array, which creates a list

               Set rtitem1 = newDoc1.CreateRichTextItem( "Body" )

Commented:
oops i didn't see that the subject changes for the person who is in cc and to list.. Will try giving some other code


partha
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

Commented:
Oops, missed the last line, could have made this simpler:

I want to send it to tdoc.Assignee and cc it to tdoc.Assignee_1 and also I want to include the link. Currently the link is not going in the e-mail to them.

But I'm confised.  You say you want to send to one person, and cc two people.  But in your instructions, you show only a single CC.  That's the easiest thing in the world (ok, hyperbole), not requiring arays of any sort, which is what partha gavae you... add one line to teh first half, drop the whole second half.

If you really want to cc TWO people, you have to use what I gave in the first post.  of course, I selected the NewDoc1 section; you could use NewDoc or NewDoc1, just drop the one not being used.

Commented:
I feel sending just one mail with two different subjects is not quite possible(u can substitute it with logical also !). Ideally in the subject you can mention that the person in the TO list is primary responsible and CC list is secondary repsonsible for this project and use my code ....


Commented:
Another variation... if you want to use two CC's, you can easily adapt the single CC version.

Dim NewDoc As NotesDocument
             Dim rtitem As NotesRichTextItem                              
             Set NewDoc = New NotesDocument( db )
             Set rtitem = newDoc.CreateRichTextItem( "Body" )
             NewDoc.SendTo = tdoc.Assignee
dim cc as notesItem  
set cc = newdoc.replaceItemValue("CopyTo",tdoc.Assignee_1)
cc.appendTotextList XXXXXXX 'where XXXXXX is the second CC name.  Could be, e.g., tdoc.Manager or tdoc.Assignee_2
              NewDoc.Subject = "New Ticket (" & TicketNum & ") has been Assigned to you"
             Call rtitem.AppendText("A new Ticket (" & TicketNum & ") has been opened and you are the_
                                                                                      Primary  Person Assigned to it.")
             Call rtitem.AddNewLine(1)
             Call rtitem.AppendDocLink(NewDoc, "Document Link")
             Call newDoc.Send(False)

Commented:
Good Logic Qwalette !

Partha

Commented:
partha has a good point.... the subject and body must be the same across both.  The subject is OK as you were already using teh same subject for both.  The body, might need a little work.  How about? ...


Call rtitem1.AppendText("A new Ticket (" & TicketNum & ") has been opened_
                                                                                         and you are assigned to it.")
Call rtitem1.AppendText(tdoc.Assignee & " is the Primary Assignee")
Call rtitem1.AppendText(tdoc.Assignee_1 & " is the Secondary Assignee")
             

Commented:
Now let's talk about your problme with the link:

Call rtitem.AppendDocLink(Doc, "Document Link")

Partha correctly points out that Doc was never used earllier in the script.  Obviously, we either only see part of the script (tdoc isn't decalred either, but from you say, it does work), or there are global variables being referenced here.

The first thing  would wonder is whether you perhaps meant to write:

Call rtitem.AppendDocLink(tdoc, "Document Link") 'tdoc
  not
Call rtitem.AppendDocLink(Doc, "Document Link") 'Doc


Or, perhaps that's a bad guess, and Doc is really correct.  If Doc really exists, then you shoudl get the DocLink, UNLESS there are one of two problems:

a) Doc was never saved
b) Database does not have a default view

You can't create a doc link from an unsaved document.  That's (a). What about (b)?  Well, when a docLin is constructed, it includes three references:
1) database
2) view
3) document

Obvisouly, we need (3), because we are referencing the document.  ALmost as obvisouly, we need (1), because the document reference is to the UniversalID, which uniqeuly identifies the document WITHIN the database... but how do you know which database to use in the first place?  So, we need (1).

Why (2)?  Becase of two things.  #1, there can be a form fomula asociated with a view.  if you opened the document from a particular view, and a form formula on the view caused it to display using an alternate form, then the link needs to cause the same form formula to be used, or the recipient of the link may see something different from the sender.  So, we need to include a view.  Another reason is to ensure that the user clicking the link has access, since views can be read-protected.  his doesn't make a lot of sense to me, but it made sense to someone in Iris during Release 2.0.

But what does that haveto do with having a defauklt view in the database?  Well, it is possible to open a document without a view -- e.g., new document (saved of course!), which has no view.  Or via unread scanning.  or via LotusScript that opens a document directly from NotesUiWorkspace.  Lotus didn't allow the view to be null in the docLink, so SOMETHING has to go there.  That something is a reference to the default view.  If you haev no default view, Notes chokes.

Commented:
WOW what a explanation !.. Points are gone for me....

Partha

P.S: Qwalette, i am collecting all your good explanations like this and forming a small "How stuff works" database internally ... copyrights Partha ;-)

Author

Commented:
Thats a Quality explanation Qwaletee. Appretiate that.
Now like i said before, I did not show you the entire code. There is lot more code upfront of this code which will create a tdoc document. Right now the link is not working. I've used your code above and it is sending the e-mail and also cc'ing two members. Thats working fine except the link.

Now I want to send the tdoc link. THe tdoc is saved before this code.
I put the code like this now:

Dim Z450 As String                  
Dim NewDoc As NotesDocument
Dim rtitem As NotesRichTextItem                                                
Set NewDoc = New NotesDocument( db )
Set rtitem = newDoc.CreateRichTextItem( "Body" )                  
NewDoc.SendTo = tdoc.Assignee
Dim cc As notesItem  
Set cc = newdoc.replaceItemValue("CopyTo",tdoc.Assignee_1)
Let Z450 = "Z450/COMPANY/NAME"                  
cc.appendTotextList Z450
NewDoc.Subject = "New Ticket (" & TicketNum & ") has been Assigned to you"
Call rtitem.AppendText("A new Ticket (" & TicketNum & ") has been opened. If you are in the To field of this email then you are the Primary Person Assigned and should take action. The Secondary Person Assigned is cc'd.")
Call rtitem.AddNewLine(1)                                                      
Call rtitem.AppendDocLink(tdoc, "Document Link")
Call newDoc.Send(False)
 

But the tdoc, "Document Link" is not working. It is not sending the link. When I run the agent it says the following:
Couldn't get default view ID for database C:\NotesDB\z450.nsf

Commented:
Be sure to have one of the views in your database designated as the 'Default when database is first opened'. I usually create a view that shows all documents in the database and make it the default.

Partha

Author

Commented:
boooooootiful.... Its working like a charm... Its sending the link ...

I'm giving 50 points to Partha and 90 points to Qwaletee...

Guys one last thing.

I want to include this and its not working.

Call rtitem1.AppendText(tdoc.Assignee & " is the Primary Assignee")
Call rtitem1.AppendText(tdoc.Assignee_1 & " is the Secondary Assignee")

Basically I want to show who the primary assignee and secondary assignee in the body.

Why did you put rtitem1 up there ?

I did this and its not working.

                  Dim Z450 As String                  
                  Dim NewDoc As NotesDocument
                  Dim rtitem As NotesRichTextItem                                                
                  Set NewDoc = New NotesDocument( db )
                  Set rtitem = newDoc.CreateRichTextItem( "Body" )                  
                  NewDoc.SendTo = tdoc.Assignee
                  Dim cc As notesItem  
                  Set cc = newdoc.replaceItemValue("CopyTo",tdoc.Assignee_1)
                  Let Z450 = "xxxxxxxxxx"                  
                  cc.appendTotextList Z450
                  NewDoc.Subject = "New Ticket (" & TicketNum & ") has been Assigned to you"
                  Call rtitem.AppendText("A new Ticket (" & TicketNum & ") has been opened. If you are in the To field of this email then you are the Primary Person Assigned and should take action. The Secondary Person Assigned is cc'd.")
                  Call rtitem.AddNewLine(1)      
                  Call rtitem.AppendText(tdoc.Assignee & " is the Primary Assignee")
                  Call rtitem.AppendText(tdoc.Assignee_1 & " is the Secondary Assignee")                  
                  Call rtitem.AppendDocLink(tdoc, "Document Link")
                  Call newDoc.Send(False)


But when I run the agent its giving me an error ==> "Type Mismatch".


           

Commented:
do like this
instead of those two lines which you gave
Call rtitem1.AppendText(tdoc.Assignee & " is the Primary Assignee")
Call rtitem1.AppendText(tdoc.Assignee_1 & " is the Secondary Assignee")

replace with  this method

Forall x in tdoc.Assignee
primaryassignee = primaryassignee + x + ","
end forall
primaryassignee = left(primaryassignee,len(primaryassignee)-1)

forall x in tdoc.Assignee_1
secondaryassignee = secondaryassignee + x + ","
endforall
      secondaryassignee = Left(secondaryassignee,Len(secondaryassignee)-1)

Call rtitem1.AppendText(primaryassignee & " is the Primary Assignee")
Call rtitem1.AppendText(secondaryassignee & " is the Secondary Assignee")

Partha

Author

Commented:
I guess the problem is with tdoc.Assignee and tdoc.Assignee_1 becuase both the fields in the form have type called "Names".

Commented:
The problem is lotus is expecting an array and u are giving just the name without the subscript

in the sense this will work
Call rtitem1.AppendText(tdoc.Assignee(0) & " is the Primary Assignee")
Call rtitem1.AppendText(tdoc.Assignee_1(0) & " is the Secondary Assignee")


But it will print only one primary assignee and one secondary assignee

Partha

Author

Commented:
Geat job partha, its working great now. Thanks for all your help guys

Author

Commented:
Guys, One thing here. There is a problem with this code here

Forall x in tdoc.Assignee
primaryassignee = primaryassignee + x + ","
end forall
primaryassignee = left(primaryassignee,len(primaryassignee)-1)

forall x in tdoc.Assignee_1
secondaryassignee = secondaryassignee + x + ","
endforall
    secondaryassignee = Left(secondaryassignee,Len(secondaryassignee)-1)

The values in this are appending.

when it sends the email the values are appending in this. Not sure why

Commented:
Yeah , the single variable is going to contain all the names... How else do you want it

Partha

Author

Commented:
If I do this will it work

                                                Delete primaryassignee
                  Delete secondaryassignee
                  Forall x In tdoc.Assignee
                        primaryassignee = primaryassignee + x + ","
                  End Forall
                  primaryassignee = Left(primaryassignee,Len(primaryassignee)-1)
                  
                  Forall x In tdoc.Assignee_1
                        secondaryassignee = secondaryassignee + x + ","
                  End Forall
                  secondaryassignee = Left(secondaryassignee,Len(secondaryassignee)-1)

Author

Commented:
I mean one e-mail should contain only one name in Primaryassignee and one name in Secondary assignee.

Now like I said before the tdoc.Assignnee and tdoc.Assignee_1 are populated from the input file. So if the input file has 5 records then there will 5 values in tdoc.Assignee one at a time.

So when the first e-mail is sent it should only have only have one value.
when the second e-mail is sent it should only have the second value in the e-mail
Commented:
What is the problem in the code
IS the primaryassignee or secondaryassignee is null.

Declare Primaryassignee ,s econdaryassignee if  u wnat

SO ideally cahnge the code like this and let me know whetehr it works

dim primaryassignee as string

dim secondaryassignee as string
primaryassignee = ""
secondaryassignee = ""

Forall x In tdoc.Assignee
                    primaryassignee = primaryassignee + x + ","
              End Forall
              primaryassignee = Left(primaryassignee,Len(primaryassignee)-1)
             
               Forall x In tdoc.Assignee_1
                   secondaryassignee = secondaryassignee + x + ","
              End Forall
              secondaryassignee = Left(secondaryassignee,Len(secondaryassignee)-1)

Author

Commented:
Cool, I'm Jumping and Pumping now.

Thanks guys

Commented:
In the sense, the second email should give for the second ticket number ?.. IF yes then the code needs to be changed..

Partha

Commented:
Good that it works !

Partha

Author

Commented:
Thanks guys,

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial