Script Help Needed

Hello all. Sorry for what may appear to be a double post. I abandoned the script from the earlier post and I’m trying a new script because I just couldn’t get it working.

Here’s what I’m trying to do. I have a form that based on a date field (called CLOSEDATE) needs to send an email reminder to a user (username is in field called NOTIFY1 in “John Doe” format) six months from that date (6 month date already stored in a computed field called REMINDERDATE). I do not get an error message when using the debugger but the appointment does not get set on the calendar. When looking at the variables in the debugger, I’ve noticed that “StartDate”, “EndDate” and Principal have “” values. Does anyone see what I may be doing wrong in the following code?

Thanks in advance

REM {Create Followup Reminder Email}

Dim ws As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim PRIN As String

Dim Date1 As String

Dim Princ As String

Date1= Cstr(ReminderDate)

Princ = Cstr(Notify1)

Set uidoc = ws.CurrentDocument	

Dim db As NotesDatabase  

REM {Send Appointment Reminder to User Listed in NOTIFY1 Field

Dim Session As New NotesSession	

Dim mdoc As NotesDocument	

Dim db2 As New NotesDatabase("" , "names.nsf") 

Set mdoc = db2.createdocument

mdoc.form = "Appointment"

mdoc.AppointmentType = "4"

mdoc.subject = "Followup Reminder"

mdoc.Body = "Please contact your potential client "

mdoc.StartDate = Date1

mdoc.EndDate = Date1

mdoc.StartTime = "10:00 AM EST"

mdoc.EndTime = "10:15 AM EST"

mdoc.Principal = Princ

Call mdoc.Save( False, False )

Subject: Script Help Needed

You are creating the Appt doc in the local Names.nsf(aka the address book), should it not be in the mail file?

Subject: RE: Script Help Needed

Oops. Yes, that’s true. How would I get a handle of the users mail file instead?

Would inserting Call db2.OpenMail in place of that line do the trick? I still have the issue of the fields returning blank values.

Subject: RE: Script Help Needed

Your start and end date problem is

Date1= Cstr(ReminderDate)

ReminderDate is not set. I assume you meant this to be

Date1= uidoc.FieldGetText(“ReminderDate”)

I would suggest Date1 be a NotesDateTime and then. You can probably get away with it here because the person running the code is updating their own calendar.

Dim Date1 as NotesDateTime

Set Date1 = New NotesDateTime( uidoc.FieldGetText(“ReminderDate”) )

As for getting your mail, there are a lot of discussion on this form just pick one! :slight_smile:

Subject: RE: Script Help Needed

Now I get an error that says that the mail database has not been opened yet. I noticed in the error that it referenced a different server name (current server) not our mail server. How do I get it to open the mail database from the mail server?

'Create Followup Reminder Email

Dim ws As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim PRIN As String

Dim Date1 As String

Dim Princ As String

Date1= Cstr(ReminderDate)

Princ = Cstr(Notify1)

Set uidoc = ws.CurrentDocument	

Dim db As NotesDatabase  

REM {Send Appointment Reminder to User Listed in ORIG Field

Dim Session As New NotesSession	

Dim mdoc As NotesDocument	

Dim db2 As New NotesDatabase("" , "") 

Call db2.OpenMail

Set mdoc = db2.createdocument

mdoc.form = "Appointment"

mdoc.AppointmentType = "4"

mdoc.subject = "Followup Reminder"

mdoc.Body = "Please contact your potential client "

mdoc.StartDate = Date1

mdoc.EndDate = Date1

mdoc.StartTime = "10:00 AM EST"

mdoc.EndTime = "10:15 AM EST"

mdoc.Principal = Princ

Call mdoc.Save( False, False )

Subject: RE: Script Help Needed

From the notes help about OpenMail

For a script to use this method, it must run either on a workstation or on the agent owner’s mail server. Otherwise, it raises an error, since scripts running on servers cannot access databases on other servers.

Try using the notessession class method GetDatabase. You also need to implement what Stephen put in his post.

Subject: RE: Script Help Needed

Just noticed that the appointments are appearing in the “Meetings” view but still not on the calendar and with an error when I try to open it. I think that several fields are text when they should be dates based on looking at the variables in the debugger. My confusion comes into play when I have date fields on the form yet they appear as text in the debugger. I’ve tried DIMMING them as NotesDateTime and as TEXT then using CDat. I’m struggling with that concept at the moment.

'Create Followup Reminder Email

Dim ws As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim PRIN As String

Dim Date1 As String

Dim Date2 As Variant	

Dim Princ As String

Set uidoc = ws.CurrentDocument	

Dim N As String

N = uidoc.FieldGetText("Notify1")

Princ = "CN=" & N & "/O=SMF"

Date1 = uidoc.FieldGetText("ReminderDate")

Date2 = Cdat(Date1)

Dim db As NotesDatabase  

REM {Send Appointment Reminder to User Listed in ORIG Field

Dim Session As New NotesSession	

Dim mdoc As NotesDocument	

Dim db2 As New NotesDatabase("" , "") 

Call db2.OpenMail

Set mdoc = db2.createdocument

mdoc.form = "Appointment"

mdoc.AppointmentType = "4"

mdoc.subject = "Followup Reminder"

mdoc.Body = "Please contact your potential client "

mdoc.StartDate = Date2

mdoc.EndDate = Date2

Dim ST As Variant

Set ST = Cdat("10:00:00 AM EDT")

mdoc.StartTime = ST

Dim ET As Variant

Set ET = Cdat("10:15:00 AM EDT")

mdoc.EndTime = ET

mdoc.Principal = Princ

mdoc.Alarms = "1"

Dim CDT As String

CDT = Cdat(Date1) & "" & Cdat("10:00 AM EDT")

mdoc.CalendarDateTime = CDT

Dim EDT As String

EDT = Cdat(Date1) & " " & Cdat("10:15 AM EDT")

mdoc.EndDateTime = EDT

mdoc.MeetingType = "1"

mdoc.SequenceNum = Cint("1")

mdoc.UpdateSeq = Cint("1")

Call mdoc.Save( False, False )

Subject: RE: Script Help Needed

FYI, Cdat Type and NotesDateTime Type and NOT the samething (not really clear the first time you read it, IMO).

The key part in the help is:

  • The data type of the return value is a Variant of DataType 7 (Date/Time)

It’s Not a NotesDateTime.

You need to change all your date times to NotesDateTime.

You can take most of what you’ve done and just have 1 tmpDateTime value dim to start.

Then everywher you do an assignment for a date or date/time… Just change it to

Set SD = New tmpDateTime( string_date ) ’ For just a date OR

Set SDT = New tempDateTime( string_date + " " + string_time ) ’ For Date and Time.

BTW, if you like I can post a overall piece of code for when I create a calendar entry. I just figured you were learning more this way.

Subject: RE: Script Help Needed

Stephen, thanks for being patient. yes, I am learning and willing to go the trial and error route as I have been with this project. However, if you have code that shows me a better way to do this I would greatly appreciate it. I think that seeing your version would provoke the thought process a little easier. I think that I’ve been hammering away at this code for too long and it’s making me spin LOL

With that said, I do have a calendar appointment appearing on my calendar now but it’s still not quite there yet. When I go to open it, it gives an error referencing the start date. I believe that this field is not formatted correctly and will look closer at this. Please send your version so that I can compare it to what I’ve done.

Thanks!

'Create Followup Reminder Email

Dim ws As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim PRIN As String

Dim Date1 As String

Dim Date2 As Variant	

Dim Princ As String

Set uidoc = ws.CurrentDocument	

Dim N As String

N = uidoc.FieldGetText("Notify1")

Princ = "CN=" & N & "/O=SMF"

Date1 = uidoc.FieldGetText("ReminderDate")

Date2 = Cdat(Date1)

Dim db As NotesDatabase  

REM {Send Appointment Reminder to User Listed in ORIG Field

Dim Session As New NotesSession	

Dim mdoc As NotesDocument	

Dim db2 As New NotesDatabase("" , "") 

Call db2.OpenMail

Set mdoc = db2.createdocument

mdoc.form = "Appointment"

mdoc.AppointmentType = "4"

mdoc.subject = "Followup Reminder"

mdoc.Body = "Please contact your potential client "

mdoc.StartDate = Date2

mdoc.EndDate = Date2

Dim ST As String

ST = uidoc.FieldGetText("ReminderTime")

Dim ST2 As Variant

ST2 = Cdat(ST)

mdoc.StartTime = ST2

Dim ET As String

ET = uidoc.FieldGetText("ReminderEndTime")

Dim ET2 As Variant

ET2 = Cdat(ET)

mdoc.StartTime = ST2

mdoc.EndTime = ET2

mdoc.Principal = Princ

mdoc.Alarms = "1"

Dim CD As String

CD = uidoc.FieldGetText("CDT")

Dim CDT2 As Variant

CDT2 = Cdat(CD)

mdoc.CalendarDateTime = CDT2

Dim EDT As String

EDT = Date1 & " " & ET

Dim EDT2 As Variant

EDT2 = Cdat(EDT)

mdoc.EndDateTime = EDT2

mdoc.MeetingType = "1"

mdoc.SequenceNum = Cint("1")

mdoc.UpdateSeq = Cint("1")

Call mdoc.Save( False, False )

Subject: RE: Script Help Needed

This is older code, originally developed for Lotus Notes 4.5 so it may need a few updates for the current version of the calendar.

I see my code originally, had a Start and EndDate on fhe form, I think you have that also… So I’ve left my code alone. However, if not you should take the stuff from the earlier posting about taking the date and time as string and convert them to a NotesDate time.

I tried to strip out stuff you don’t need, I had various other options the on the form that you don’t need to see / worry about. Hope this helps?

On my form I have a field called StartDate - the date of a meeting and TimeRange (timerange picker) which gave you the start and end time of the meeting:

Dim db As NotesDatabase

Dim DBProfile As NotesDocument



Dim mailServer As String

Dim mailFile As String

Dim message As String



Set ws = New NotesUIWorkspace     

Set s = New NotesSession



Set db = s.Currentdatabase

Set uiDoc = ws.Currentdocument

Set Doc = uiDoc.document

	

MailServer = s.GetEnvironmentString("MailServer",True)

MailFile = s.GetEnvironmentString("MailFile",True)



Dim Maildb As New NotesDatabase( mailServer, mailFile )



If Not Maildb Is Nothing Then

	

	Set calDoc = New NotesDocument (Maildb)

	

	Dim tr As NotesDateRange

	Dim rtitem As NotesRichTextItem

	Dim Subj As String

	Dim Team As String

	Dim sDate As New NotesDateTime( "" )

	Dim eDate As New NotesDateTime( "" )

	

	caldoc.Form="Appointment"

	caldoc.Broadcast=""

	caldoc.Categories=""

	caldoc.CHAIR=Doc.TeamLeader

	caldoc.Duration = 1

	caldoc.ExcludefromView="D"

	caldoc.From=Doc.TeamLeader

	caldoc.ORGDONTDOUBLEBOOK="1"

	caldoc.ORGTABLE="C0"

	Call caldoc.APPENDITEMVALUE("$PublicAccess","1") 

	Call caldoc.AppendItemValue("$BusyName",s.username)

	Call calDoc.AppendItemValue("$BusyPriority","1")

’ ----- Start of StartDateTime and TimeRange work -----

	sDate.lslocaltime = doc.StartDateTime(0)

	Set follupdate=New NotesDateTime(sDate.localtime)



	Set tr=s.CreateDateRange()     

	Set tr.StartDateTime = sDate

	eDate.lslocaltime = doc.EndDateTime(0)

	Set tr.EndDateTime = eDate

	

	Set caldoc.CalendarDateTime=follupdate

	Set caldoc.ReminderTime=follupdate

	Set caldoc.StartDate=follupdate

	Set caldoc.StartDateTime=follupdate

	Set caldoc.TimeRange=tr

’ ----- End of StartDateTime and TimeRange work -----

	Team = Doc.TeamName(0)

	

	Dim sDateTime As String

	sDateTime = sDate.DateOnly & ", at [" & sDate.TimeOnly & "-" & eDate.TimeOnly & "] " 

		

	Set calDoc.EndDateTime = eDate               

		

	Subj = "Meeting Agenda for " & Team & " on "&  sDateTime    

	If(Doc.MeetLocation(0) <> "") Then

		Subj = Subj & " in " + Doc.MeetLocation(0)

	End If

	caldoc.Subject=Subj & "."

	caldoc.AppointmentType="0"

		

	Call caldoc.APPENDITEMVALUE("_ViewIcon",160)

	Call caldoc.APPENDITEMVALUE("$NoPurge",eDate)

		

	Set rtitem = New NotesRichTextItem( caldoc, "Body" )

	Call rtitem.AppendText( NameImplode(Doc.CalledBy,", ") & " has called a meeting for the " & Team & " team, on: ")

	Call rtitem.AppendText(sDateTime)

	If(Doc.MeetLocation(0) <> "") Then

		Call rtitem.AppendText( " in " + Doc.MeetLocation(0) )

	End If

	Call rtitem.AppendText(".") 

		

	message = "The meeting has been added to your calendar."

		

      ' Alarm information



	Call calDoc.AppendItemValue("$Alarm",1)

	Call calDoc.AppendItemValue("$AlarmDescription",Subj & ".")

	Call calDoc.AppendItemValue("$AlarmOffset",-DBProfile.AlarmMinutes(0))

	

	Call rtitem.AddNewLine(2)

	Call rtitem.AppendText ("You can learn more by double clicking on the following Lotus Notes doclink ==> ")

	Call rtitem.Appenddoclink(doc, Doc.Team(0) & " team.")

	Call rtitem.AddNewLine(1)

	

	Call caldoc.ComputeWithForm(False, False)

	Call caldoc.save(True,False,False)

	Msgbox(message)

	

End If

Subject: RE: Script Help Needed

Steven, thank you very much for the example. I am leaving soon for the weekend but will take a very close look at how you were able to accomplish the task with your script and try to tweak my code where needed. I hope to be back onto this project by Monday or Tuiesday so I’ll let you know how I made out in a few days.

Have a great weekend!