Outlook Automation : Appointment Item

Debbie140Debbie140 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

Comments

  • kinekine Member Posts: 12,562
    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)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • fbfb Member Posts: 246
    Does this work?
    oAppt.Start := DATI2VARIANT(Start,Time);
    
  • kinekine Member Posts: 12,562
    I think NO...

    Start is Date for Navision .... not DateTime... Any conversion does not help... :?
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Debbie140Debbie140 Member Posts: 52
    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.
  • kinekine Member Posts: 12,562
    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)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • fbfb Member Posts: 246
    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");
    
  • kinekine Member Posts: 12,562
    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:
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Dmitry_ChadaevDmitry_Chadaev Member Posts: 52
    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,
    Dmitry
  • tameemabdullahtameemabdullah Member Posts: 17
    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 AM
Sign In or Register to comment.