Wednesday, July 8, 2009

Import data from application to Outlook Calender through Javascript

// JScript File
var formattedDate;
var olAppointmentItem = 1; //fixed for different properties of outlook object
//EXPORT to OUTLOOK
function ExportDataToOutlook()
{
var duration = 120; //number of minutes (duration in Outlook being in minutes)
SetTimeForAppointment();//time of appoinment was fixed
try
{
var objOutlook = new ActiveXObject( "Outlook.Application" );
}
catch(e)
{
alert("Outlook needs to be installed on the machine for data to export.");
return false;
}
var objAppointment = objOutlook.CreateItem(olAppointmentItem);
objAppointment.Subject = "Appointment exported to Outlook from a web application";
objAppointment.Body = "This is an appointment being exported into Outlook using a web-application.";
objAppointment.Start = formattedDate;
objAppointment.Duration = duration;
objAppointment.ReminderSet = false;
objAppointment.Save();
alert("An appointment was exported successfully to your Outlook calendar in todays date.");
return true;
}
function SetTimeForAppointment()
{
var currentDate = new Date();
var month = currentDate.getMonth();
var day = currentDate.getDate();
var year = currentDate.getFullYear();
formattedDate = (month+1) + "/" + day + "/" + year + " 08:00AM";
}

No comments: