Options

Outlook Appointment from NAV, Time defaults to 00:00 in RTC

kakiskakis Member Posts: 7
edited 2015-06-11 in NAV Three Tier
Hi all,

I have been lurking these forums for a long time and you guys have helped me overcome a lot of issues we were facing, but I did not find anything related to what I am going write next.

I have created a codeunit which you can call from various tables to create Outlook Appointments.
However the Time of the Appointment Item.Start attribute always defaults to midnight (00:00). As a result I cannot really create Appointments automatically for them and I have to pop up the Calendar Window so that they can manually select the time.

Please note this happens only when the Codeunit is called from the RTC Client. If we use the Classic the time is set correctly.

Please find the code below.


IF NOT CREATE(Application,FALSE,TRUE) THEN
EXIT;

char13 :=13;
char10:=10;

//text:= text1 +format(char13)+format(char10)+ text2;


Namespace := Application.GetNamespace('MAPI');
Namespace.Logon;

"Appointment Item" := Application.CreateItem(1);
"Appointment Item".Start(DATI2VARIANT(date,120000T));
"Appointment Item".Subject := Type+ ' - ' + Name+' - ' +"Name 2";
"Appointment Item".Body := 'This is an automated appointment sent from NAV.'+FORMAT(char13) + FORMAT(char10) +
'Phone number(s): ' + "Phone No." + ' . ' + "Mobile Phone No.";
"Appointment Item".Duration := 60;
"Appointment Item".ReminderMinutesBeforeStart := 1;
"Appointment Item".ReminderSet := TRUE;
"Appointment Item".Location := 'Phone';
"Appointment Item".Display;
//"Appointment Item".Save;


Namespace.Logoff;
CLEAR(Application);


As you can see I commented off the "Save" and replaced it with "Display" in order for the window to pop up.
Any kind of input will be appreciated!
I apologise in advance if something is not clear, English is not my first language.

Regards

Constantine

Comments

  • Options
    kinekine Member Posts: 12,562
    What I remmember is, that in some versions and in some automations, the datetime parameter was presented as date parameter in NAV (thus cutting the time...). There were special automations to just go around this issue (wrappers) to set the date and time correctly. Under RTC, you can try to use the DotNet instead automations.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    kakiskakis Member Posts: 7
    Thanks for the reply, I was hoping I was doing something wrong.. ](*,) Ah well I ll have to play around some more then.

    Thank you for helping!
  • Options
    kinekine Member Posts: 12,562
    But I am not sure if this is the situation, because I see .Start as Variant, not Date...

    When I looked into Codeunit 5073 from NAV 4, I see>
    AppointmentItem.AllDayEvent := Todo."All Day Event" ;
    
    AppointmentItem.Subject := Todo.Description;
    AppointmentItem.Location := Todo.Location;
    AppointmentItem.Importance := Todo.Priority;
    StartTime := SkipSeconds(Todo."Start Time");
    AppointmentItem.Start := DATI2VARIANT(Todo.Date,StartTime);
    AppointmentItem.Duration := ROUND(Todo.Duration / 60 / 1000,1);
    AppointmentItem.AttainDbCompanyName := COMPANYNAME;
    AppointmentItem.AttainSalespersonCode := Todo."Salesperson Code";
    AppointmentItem.AttainTodoNo := Todo."No.";
    AppointmentItem.AttainContextURL := OutlookContactHandler.CreateTaskLink(Todo."Organizer To-do No.");
    AppointmentItem.AttainTodoVersionNo := Todo."Version No.";
    

    It means it should work. Try first to add this
    "Appointment Item".AllDayEvent := False;
    
    before you set the Start...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    kakiskakis Member Posts: 7
    Tried it, still defaults to 00:00..

    Ah well, I ll try to redo the whole thing but with using DotNet variables instead of Automation variables.

    Lets see how that will go.
  • Options
    kakiskakis Member Posts: 7
    Long time overdue. Using dotNet variables in rtc solved the problem.

    This is the code I used:


    outlookApp := oAppClass.ApplicationClass();
    oAppointment := oAppointmentClass;

    oAppointment := outlookApp.CreateItem(1);
    oAppointment.Subject := Subject;
    oAppointment.Body := Body;
    //oAppointment.Location := 'Appointment location';
    // Set the start date
    oAppointment.Start := CREATEDATETIME(StartDate,StartTime);
    // End date
    oAppointment."End" := CREATEDATETIME(StartDate,EndTime);
    // Set the reminder 15 minutes before start
    oAppointment.ReminderSet := TRUE;
    oAppointment.ReminderMinutesBeforeStart := 15;
    //Setting the sound file for a reminder:
    oAppointment.ReminderPlaySound := TRUE;
    //set ReminderSoundFile to a filename.
    //Setting the importance:
    //use OlImportance enum to set the importance to low, medium or high
    //oAppointment.Importance := Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh;
    //oAppointment.BusyStatus := Microsoft.Office.Interop.Outlook.OlBusyStatus.olBusy;;
    //oAppointment.Save();
    oAppointment.Display(oAppointment);


    Parameters:
    Var Name DataType Subtype Length
    No Subject Text 1000
    No Body Text 1000
    No StartTime Time
    No EndTime Time
    No StartDate Date
    No location Text 1000

    Variables:
    Name DataType Subtype Length
    outlookApp DotNet 'Microsoft.Office.Interop.Outlook, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.Microsoft.Office.Interop.Outlook.Application
    oAppClass DotNet 'Microsoft.Office.Interop.Outlook, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.Microsoft.Office.Interop.Outlook.ApplicationClass
    oAppointment DotNet 'Microsoft.Office.Interop.Outlook, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.Microsoft.Office.Interop.Outlook.AppointmentItem
    oAppointmentClass DotNet 'Microsoft.Office.Interop.Outlook, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.Microsoft.Office.Interop.Outlook.AppointmentItemClass
    olItemType DotNet 'Microsoft.Office.Interop.Outlook, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.Microsoft.Office.Interop.Outlook.OlItemType
    oMailItem DotNet 'Microsoft.Office.Interop.Outlook, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.Microsoft.Office.Interop.Outlook.MailItem
  • Options
    evandeveerdonkevandeveerdonk Member Posts: 49
    Hi Kakis,

    not sure if you already solved the problem, and how urgent this is for your customer, but we had the same kind of problems before. Things not working properly in the integration, no debugging possible, and not flexible.

    We have created a new NAV-Outlook Synchronisationautomation where you, as a developper, can make changes very easy.

    Perhaps this could be interesting for you.
    See our website http://www.vssolutions.nl

    If you still have this issue, and your customer wants you to fix it: here's your solution

    Ernst
    http://www.vssolutions NAV-Outlook synchronisation re-invented.
  • Options
    tameemabdullahtameemabdullah Member Posts: 17
    Hi Kakis,

    Did you get this to work setting the start time and end time of an outlook meeting?

    I have tried using your method with a dotnet variable and even though in NAV it has the correct time e.g. StartTime = 1600T when the actual meeting is created it seems to read the time incorrectly and creates a meeting at 0600 AM

    I have tried also changing my regional date and time settings on the computer/server so that they are all in 24 hour format as well but still no difference.

  • Options
    tameemabdullahtameemabdullah Member Posts: 17
    Just figured this out. The timezone that was trying to recalculate the start time according to UTC...

    Changed the call to this and it worked!

    oAppointment.StartUTC := CREATEDATETIME(StartDate,StartTime);
    oAppointment.EndUTC := CREATEDATETIME(StartDate,EndTime);
Sign In or Register to comment.