Link to home
Start Free TrialLog in
Avatar of magnex
magnex

asked on

How can I create an appointment from another database

Hey experts,

I've a problem.
I've a purchase database, and in this database I've a lot of information about my customers.
In that document I've a date field (for my next appointment with that customer) and a subject field.
What I want is an action button, that when I click on it, it makes an appointment in my calendar (mail db), the date from the appointment and the subject are available in the document.

How can I do this ?
Avatar of Bozzie4
Bozzie4
Flag of Belgium image

Here's some code to do that.  Please adjust it to your own needs.


Dim s As NotesSession
Dim Adb As notesdatabase
Dim maildb As notesdatabase
Dim view As notesview
Dim w As notesUiworkspace
Dim doc As notesdocument
Dim doct As notesdocument
Dim reg As New NotesRegistration
Dim uname As String
Dim retmailserver As String
Dim retmailfile As String
Dim nm As String

Set s =New NotesSession
nm=s.username
Set w=New NotesUIWorkspace
Set doc=w.currentdocument.document
Dim userName As New NotesName(nm)
uname=UserName.Abbreviated

t=s.currentdatabase.server
reg.RegistrationServer = s.currentdatabase.server
Call reg.GetUserInfo(uname, retmailserver, retmailfile)
Set MailDb=New NotesDatabase(retmailserver, retmailfile)

set doct=maildb.CreateDocument
Call doct.replaceItemValue("Form","Appointment")

Call doct.replaceItemValue("ReAssignMark","Yes")
Call doct.replaceItemValue("AppointmentType","0") '0 for Appointment
Call doct.replaceItemValue("Subject", " SUBJECT GOES HERE ")
Call doct.replaceItemValue("$AlarmUnit", "M")
Call doct.replaceItemValue("$Alarm", 1)
Call doct.replaceItemValue("$AlarmMemoOptions", "")
Call doct.replaceItemValue("$AlarmDescription", contacts)
Call doct.replaceItemValue("$AlarmOffset", -1)
Dim ndt As NotesDateTime
t=Cstr(Datevalue(Today))+" 13:15:00"
Set ndt = New NotesDateTime(t)
Dim ndt1 As NotesDateTime
t=Cstr(Datevalue(Today))+" 13:20:00"
Set ndt1 = New NotesDateTime(t)
Call doct.replaceItemValue("STARTDATETIME", ndt)
Call doct.replaceItemValue("StartTime", ndt.TimeOnly)
Call doct.replaceItemValue("EndTime", ndt1.TimeOnly)
Call doct.replaceItemValue("StartDate", ndt.DateOnly)
Call doct.replaceItemValue("EndDate", ndt1.DateOnly)
Call doct.replaceItemValue("CalendarDateTime", ndt)
Call doct.ComputeWithForm(True,False)
Call doct.Save(True,True)

cheers,

Tom
Avatar of hshevitz
hshevitz

You say that you have the date and subject available in the customer document in the purchase database. Does the date field include a time for this appointment? The above code from Bozzie4 will probably work with some small changes to get the date information from your customer document, but it will need a "time" to create the appointment. If this will only be a reminder, then this can be done with only the date and appending  " 12:00:00 AM" to the date when creating the NotesDateTime object. Sounds a little complicated, but that's the way the calendar entries work in Notes.

Tell us what you need for the appointment document.

HS
Magnex,

I need the field names for Subject and the apopintment date field.  If you have acess to designer, that will be easy to find.  Otherwise:
 * highlight the document in the view
 * choose File -> Database -> Properties
 * change "database" to "document" in the proerties title
 * click on the second tab ("triangle" tab)
 * in the left half, scroll to the top
 * click on each field name on the left, and see if the value matches subject or the date on the right.  Tell me those field names.
Const SubjectField = "SUBJECT" 'change as appropriate
Const DateField = "APPOINTMENT" 'chaneg as appropriate

Dim ws as new notesUiWorkspace
Dim uiDoc as notesUiDocument
Set uiDoc = ws.currentDocument
Dim Subject as string, position as string
Subject = uiDoc.fieldGetText(SubjectField)
Position = uiDoc.FieldGetText(DateField)
If ucase(right(Position,1)) <> "M" then Position = position & " 9:00 AM"

Dim s As new notesSession
Dim db As notesDatabase
Set db = s.getDatabase("", "")
db.openMailDB
Dim doc As notesDocument
Set doc = db.createDocument
doc.replaceItemvalue "Form", "Appointment"
Dim dateTime As NotesDateTime
Set dateTime = s.createDateTime(position)
doc.replaceItemvalue "$Alarm", 1
doc.replaceItemvalue "$AlarmOffset", 0
MsgBox "Setting reminder/alarm - " & dateTime.lslocalTime & " - " & Subject
doc.replaceItemvalue "startDateTime", dateTime
doc.replaceItemvalue "endDateTime", dateTime
doc.replaceItemvalue "calendarDateTime", dateTime
doc.replaceItemvalue "Subject", Subject
doc.replaceItemvalue "startTime", dateTime
doc.replaceItemvalue "appointmentType", "3"
doc.replaceItemvalue "Alarms", "1"
doc.replaceItemvalue "startDate", dateTime
doc.replaceItemvalue "endDate", dateTime
doc.replaceItemvalue "endTime", dateTime
doc.replaceItemvalue "SendTo", invitees
doc.Save True, True
doc.putInFolder "($Alarms)"


I'm telling ya, calendar entries are tricky. You must have specific values in all 6 fields:

StartDateTime
StartDate
StartTime
EndDateTime
EndDate
EndTime

Each one needs the value for the component:

StartDateTime needs a value like 08/12/2003 04:00:00 AM
StartDate needs a value like 08/12/2003
StartTime needs a value like 04:00:00 AM

and so on.

If all this is correct, the calendar will display the document correctly.

HS
Avatar of magnex

ASKER

when I use the above code I get the error "Not a sub or function name OpenMailDb"
It's

Call db.OpenMail

instead of db.openmaildb

cheers,

tom
Avatar of magnex

ASKER

I still get an error "Not a member Openmaildb"
Avatar of magnex

ASKER

bozzie when I ty your code
He makes a calendar entry, but  I can't open it.
"Error trying to open document : Note item not found"
"Field StartDate_2: Array index out of bounds"
Avatar of magnex

ASKER

in the example of qwaletee the problem with openmail is solved.
But, he creates now a meeting document in the calendar instead of an appointment.

Add the line

Call doct.ReplaceItemValue("EndDateTime" ,  ndt1 )

before the 'computewithform'

Should've tested it myself first, of course :-)

cheers,

Tom
And to create an appointment document,  change

doc.replaceItemvalue "appointmentType", "3"
to
doc.replaceItemvalue "appointmentType", "0"

cheers,

Tom
Avatar of magnex

ASKER

Bozzie, In your example I still get the same problem.
He also shows no time in the calendar and he makes the appointment every week again

The other example, he makes no the appointment but gives me the error "Error trying to open the document : noteitem not found" when I try to open the document but I can open the document
Hmmm.  This works for me like a charm, though.
So this code should do it for you.


      Dim s As NotesSession
      Dim Adb As notesdatabase
      Dim maildb As notesdatabase
      Dim view As notesview
      Dim w As notesUiworkspace
      Dim doc As notesdocument
      Dim doct As notesdocument
      Dim reg As New NotesRegistration
      Dim uname As String
      Dim retmailserver As String
      Dim retmailfile As String
      Dim nm As String
      Dim t As String
      
      Set s =New NotesSession
      nm=s.username
      Set w=New NotesUIWorkspace
      Set doc=w.currentdocument.document
      Dim userName As New NotesName(nm)
      uname=UserName.Abbreviated
      
      t=s.currentdatabase.server
      reg.RegistrationServer = s.currentdatabase.server
      Call reg.GetUserInfo(uname, retmailserver, retmailfile)
      Set MailDb=New NotesDatabase(retmailserver, retmailfile)
      
      Set doct=maildb.CreateDocument
      Call doct.replaceItemValue("Form","Appointment")
      
      Call doct.replaceItemValue("ReAssignMark","Yes")
      Call doct.replaceItemValue("AppointmentType","0") '0 for Appointment
      Call doct.replaceItemValue("Subject", " SUBJECT GOES HERE ")
      Call doct.replaceItemValue("$AlarmUnit", "M")
      Call doct.replaceItemValue("$Alarm", 1)
      Call doct.replaceItemValue("$AlarmMemoOptions", "")
      Call doct.replaceItemValue("$AlarmDescription", "")
      Call doct.replaceItemValue("$AlarmOffset", -1)
      Dim ndt As NotesDateTime
      t=Cstr(Datevalue(Today))+" 13:15:00"
      Set ndt = New NotesDateTime(t)
      Dim ndt1 As NotesDateTime
      t=Cstr(Datevalue(Today))+" 13:20:00"
      Set ndt1 = New NotesDateTime(t)
      Call doct.replaceItemValue("STARTDATETIME", ndt)
      Call doct.replaceItemValue("StartTime", ndt)
      Call doct.replaceItemValue("EndTime", ndt1)
      Call doct.replaceItemValue("StartDate", ndt)
      Call doct.replaceItemValue("EndDate", ndt1)
      Call doct.replaceItemValue("CalendarDateTime", ndt)
      Call doct.ReplaceItemValue("EndDateTime" ,  ndt1
' ###
      Call doct.ComputeWithForm(True,True)  
' use this when done testing:
'Call doct.ComputeWithForm(True,False)  
'###
      Call doct.Save(True,True)

cheers,

Tom
Avatar of magnex

ASKER

I used a mix of Bozzies solutions and qwaletee solution.
Everything works now fine in the client but not in the browser.
UI classes are not allowed in the browser.
So, my question is can we do the same in the browser
ASKER CERTIFIED SOLUTION
Avatar of Bozzie4
Bozzie4
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial