Outlook Automation : Appointment Item

Debbie140
Member Posts: 52
Hi
I am trying to create appointments in folders form Navision using outllok atuomation as follows:
CREATE(oApp);
oNS := oApp.GetNamespace('mapi');
oRecipient := oNS.CreateRecipient(Recipient);
oFolder := oNS.GetSharedDefaultFolder(oRecipient,9); //9 is constant for Outlook.OlDefaultCalendar.olFolderCalendar
oAppt := oFolder.Items.Add(1); //1 is constant for Outlook.OlItemType.olAppointmentItem
oAppt.Subject := Subject;
oAppt.Location := Location;
StartTime := CREATEDATETIME(Start,Time);
oAppt.Start := StartTime;
oAppt.Duration := (Duration/60000);
oAppt.ReminderSet := TRUE;
oAppt.ReminderMinutesBeforeStart := 15;
oAppt.BusyStatus(2); //2 is constant for Outlook.OlBusyStatus.olBusy
oAppt.IsOnlineMeeting := FALSE;
oAppt.Save;
CLEAR(oAppt);
The problem I am having is with the line
oAppt.Start := StartTime;
The microsoft help pages say that the start property takes a datetime and I am passing a datetime but when I compile the code I get a type conversion message saying that the start property is expecting a date only. Has anyone else had this problem?
I spoke to another developer who said that the datetime type is a recent addition to Navision so maybe Navaion doesn't recognise the datetime type required.
Any thoughts would be appriciated.
Debbie
I am trying to create appointments in folders form Navision using outllok atuomation as follows:
CREATE(oApp);
oNS := oApp.GetNamespace('mapi');
oRecipient := oNS.CreateRecipient(Recipient);
oFolder := oNS.GetSharedDefaultFolder(oRecipient,9); //9 is constant for Outlook.OlDefaultCalendar.olFolderCalendar
oAppt := oFolder.Items.Add(1); //1 is constant for Outlook.OlItemType.olAppointmentItem
oAppt.Subject := Subject;
oAppt.Location := Location;
StartTime := CREATEDATETIME(Start,Time);
oAppt.Start := StartTime;
oAppt.Duration := (Duration/60000);
oAppt.ReminderSet := TRUE;
oAppt.ReminderMinutesBeforeStart := 15;
oAppt.BusyStatus(2); //2 is constant for Outlook.OlBusyStatus.olBusy
oAppt.IsOnlineMeeting := FALSE;
oAppt.Save;
CLEAR(oAppt);
The problem I am having is with the line
oAppt.Start := StartTime;
The microsoft help pages say that the start property takes a datetime and I am passing a datetime but when I compile the code I get a type conversion message saying that the start property is expecting a date only. Has anyone else had this problem?
I spoke to another developer who said that the datetime type is a recent addition to Navision so maybe Navaion doesn't recognise the datetime type required.
Any thoughts would be appriciated.
Debbie
0
Comments
-
There is problem in representation of DateTime from Automation. Solution is in download section (NFDateTime.ocx). http://www.mibuso.com/dlinfo.asp?FileID=11 8)0
-
Does this work?
oAppt.Start := DATI2VARIANT(Start,Time);
0 -
I think NO...
Start is Date for Navision .... not DateTime... Any conversion does not help... :?0 -
Thanks for the replies
Kine is correct. The start date expects a date not a datetime so conversion does not seem to help.
I have tried to use the date time conversion ocx just to test this theory but I can't get it to work properly.0 -
Copy OCX file, register with Regsvr32, in code use:
Var Dat,Tim : Text30; DT: OCX "DateTimeConversion.DateTime" OutIT : Automation 'Microsoft Outlook 10.0 Object Library'.AppointmentItem OutApp: Automation 'Microsoft Outlook 10.0 Object Library'.Application //code start there---------- IF ISCLEAR(OutApp) THEN CREATE(OutApp); OutIt := OutApp.CreateItem(1); OutIt.Body := 'Text of Appointment body'; OutIt.Companies := 'Company 1'; OutIt.Subject := 'Subject text'; Dat := FORMAT("Starting date"); Tim := FORMAT("Starting Time"); DT.SetStart(OutIt,Dat,Tim); IF "Starting Time"=0T THEN OutIt.AllDayEvent(TRUE) ELSE BEGIN Dat := FORMAT("Ending Date"); Tim := FORMAT("Ending Time"); DT.SetEnd(OutIt,Dat,Tim); END; OutIt.ReminderSet := FALSE; OutIt.Save; //Appointment is created, you can save OutIt.EntryID to have reference for synchronization etc.
Where "Starting date" and "Starting time" and "Ending date" and "Ending time" are Date and Time variables with start and end. If Start time is 0T then event is marked as AllDay event.
8)0 -
oAppt.Start expects a Variant of sub-type VT_DATE (these are COM datatypes, not to be confused with C/AL datatypes).
DATI2VARIANT takes a C/AL Date and a C/AL Time and returns a Variant of sub-type VT_DATE -- just what oAppt.Start wants.
I'm pretty sure it works -- the following line is taken from Codeunit 5073 - ToDo Handler:AppointmentItem.Start := DATI2VARIANT(Todo.Date, Todo."Start Time");
0 -
fb: YES, you are right!
I didn't notice it before... Thanks!!! :idea:
Debbie140:
What i wrote is for Navision Financials, without VARIANT data type... :oops:0 -
Just in case ...
Have you tried to use OLWrapper.DLL (from standart Navision installation) - it is the Outlook Integration component - it wraps Outlook folders, items, events etc. I think it is safer to work with Outlook through this component - it returns error codes and descriptions in case of errors. If you call Outlook objects directly - the program just crushes when error occurs. You can take a look on Codeunits 5072 and 5073 for C/AL examples.Best regards,
Dmitry0 -
i have tried using this
AppointmentItem.Start := DATI2VARIANT(Todo.Date, Todo."Start Time");
but when the invite is created in outlook the time is ignored and all invites are created at 12:00 AM0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions