Subject: RE: Variable not visible to script library sub
Of course, sorry, I was trying to only post the relevant lines but I know the context is important…
AGENT CODE:
Sub Initialize
' 12/10/2007: Send interview letters to military applicants
Set sess = New NotesSession
Set db = sess.CurrentDatabase
user = sess.CommonUserName ' (needed for SendMilitaryLtrs sub)
Dim coll As NotesDocumentCollection
Set coll = db.UnprocessedDocuments
Dim doc As NotesDocument, nextdoc As NotesDocument
Set doc = coll.GetFirstDocument
' Set up an output file for problems:
Dim filename As String
Dim filenum As Integer
filename = "H:\My Documents\MilNoEM.txt"
filenum = Freefile()
Open filename For Output As filenum
Dim todaydate As String
todaydate = Today
Print #filenum, "Military Candidates folder auto email interview letters"
Print #filenum, todaydate
Print #filenum,
Print #filenum, "The following applicants do not have email addresses entered so were not emailed interview notices today:"
Print #filenum,
Print #filenum, "LAST NAME"; Tab (24); "FIRST NAME"
Print #filenum,
' Loop thru selected docs:
Do While Not doc Is Nothing
Set nextdoc = coll.GetNextDocument (doc)
' Get name
firstname = doc.GetItemValue ("FirstName") (0)
lastname = doc.GetItemValue ("LastName") (0)
wholename = Cstr(firstname) + " " + Cstr(lastname) ' * * * * * THIS IS NOT CARRYING OVER TO THE SUB * * * * *
' Make sure there is an email address before proceeding
emailaddr = doc.GetItemValue ("Email") (0)
If emailaddr = "" Then
Msgbox "No email address for: " + wholename ' * * * ERROR CHECKING * * *
' LOG THE NAME IN A FILE HERE:
Print #filenum, Cstr(lastname); Tab (24); Cstr(firstname)
Goto keepgoing
Else
emailstr$ = Cstr (emailaddr)
Msgbox "Email for " + wholename + ": " + emailstr$ ' * * * ERROR CHECKING * * *
End If
' Call the email sub here
SendMilitaryLtrs
keepgoing:
Delete doc
Set doc = nextdoc
Loop
Print #filenum,
Print #filenum, "All others currently in the folder but not listed above were sent emails today."
Close filenum
Msgbox "Done sending emails! See MilNoEM.txt under My Documents on your H drive for applicants with no emails.", 0 + 64 + 0 + 0, "Completed"
End Sub
SUB CODE:
Sub SendMilitaryLtrs
'12/11/2007: To auto e-mail interview letters to military applicants
Set sess = New NotesSession
Set db = sess.CurrentDatabase
Set emdoc = New NotesDocument (db)
emdoc.Form = "Memo"
' Set value of email message:
Dim messagetext As NotesRichTextItem
Set messagetext = New NotesRichTextItem (emdoc, "mainmessage")
Dim msgstyle As NotesRichTextStyle
Set msgstyle = sess.CreateRichTextStyle
Call messagetext.AddTab (1)
Call messagetext.AppendText ("We will be conducting interviews at the locations and dates listed on the attached sheet. This will be the only opportunity for interviews.")
Call messagetext.AddNewline (2)
Call messagetext.AddTab (1)
Call messagetext.AppendText ("In order to schedule an interview at one of the designated locations, call during the week of ")
msgstyle.Underline = True
Call messagetext.AppendStyle (msgstyle)
Call messagetext.Update
Call messagetext.AppendText ("December 10-14, 2007, between 8:30 am - 5:00 pm, Eastern Standard Time. ")
msgstyle.Underline = False
Call messagetext.AppendStyle (msgstyle)
Call messagetext.AppendText ("Locations and times are limited and will be allocated on a first-come, first-served basis.")
Call messagetext.AddNewline (2)
Call messagetext.AddTab (1)
Call messagetext.AppendText ("The interviews will be approximately 1 - 2 hours long and you should plan to arrive at least 15 minutes prior to your scheduled interview. Please bring ")
msgstyle.Bold = True
Call messagetext.AppendStyle (msgstyle)
Call messagetext.AppendText ("two (2) forms of personal identification; one (1) must be with a photo.")
msgstyle.Bold = False
Call messagetext.AppendStyle (msgstyle)
Call messagetext.AddNewline (2)
Call messagetext.AddTab (1)
Call messagetext.AppendText ("Failure to contact us and schedule an interview in the specified time frame will result in your name being removed from further consideration.")
Call messagetext.AddNewline (2)
Call messagetext.AddTab (1)
Call messagetext.AppendText ("Thank you for your interest.")
Call messagetext.AddNewline (2)
Call messagetext.AddTab (6)
Call messagetext.AppendText ("Sincerely,")
Call messagetext.AddNewline (3)
Call messagetext.AddTab (6)
Call messagetext.AppendText ("Office of Recruitment")
Dim rtintervmsg As NotesRichTextItem
Set rtintervmsg = New NotesRichTextItem (emdoc, "Body")
Call rtintervmsg.AppendText ("Dear " + wholename + ":") ' THIS IS NOT CARRYING OVER FROM THE AGENT * * * *
Call rtintervmsg.AddNewline (1)
Call rtintervmsg.AddNewline (1)
Call rtintervmsg.AppendRTItem (messagetext)
' Send auto email notification
addressees(0) = emailstr$ ' ADD BACK IN AFTER TESTING ' THIS IS NOT CARRYING OVER FROM THE AGENT, EITHER * * * *
'copypersons(0) = "person@us.com" ' ADD BACK IN AFTER TESTING
emailsubj = "Interviews"
emdoc.SendTo = addressees
emdoc.CopyTo = copypersons
emdoc.From = user
emdoc.MemoDt = Today
emdoc.Subject = emailsubj
Call emdoc.Send (False)
End Sub
user carries over into the sub just fine. wholename is apparently not available in the sub. Also, I switched the addressee from my own hard-coded email address (for testing) to the emailstr$ variable, and that is not carrying over, either, so I guess that is the same problem. The users are willing to forego the personalized email greeting using wholename if necessary, but obviously if emailstr$ is not available, it won’t work at all!
It must be a scope problem, yes?? I was next going to try copying the agent code into a button instead of having it in the Actions menu… Failing that, I was going to just copy all the sub code into the agent.
TIA,
Mark
P.S. (The formatting doesn’t work, either, but I’ve researched that one, nothing I’ve tried has changed, and at this point the users don’t care about bolding and underlining, as long as we can solve the email address issue.)