Wednesday, July 8, 2009

Export Data from outlook Calander to Application through javascript

function ImportAppoinments()
{
try
{
if((window.ActiveXObject))
{ // create outlook object
var objOutlook = new ActiveXObject( "Outlook.Application" );
var olAppointmentItem = 1; //fixed for different properties of outlook object

var objAppointment = objOutlook.CreateItem(olAppointmentItem);
var outlookFolderCalendar = 9;
var objNameSpace = objOutlook.GetNamespace('MAPI');
var outlookFolder = objNameSpace.GetDefaultFolder(outlookFolderCalendar);
var myOutlookItems = outlookFolder.Items;
if(myOutlookItems.count>0)
{
for(var x=1;x<=myOutlookItems.count;x++)
{
var dateOfAppointment = myOutlookItems(x).Start;
var bodyOfAppointment = myOutlookItems(x).Body;
alert(dateOfAppointment+'\n'+bodyOfAppointment);
}

}
else
{
alert('No Events');
}
return false;
}
}
catch(e)
{
alert("If MS Outlook is already there\nplease try the following steps:\nClick on Tools (Menu)=>Internet options=>\n=>Security (Tab)=>Internet=>Custom level=>\nChoose 'Enable' from 'initialize and script Activex controls not marked as safe'");
return false;
}
}

2 comments:

Unknown said...

How to view appointment for each day? I dont want to view all appointments. is there any way to get it other than searching in all appointment?

Samir said...

Thanks Rahul,
Yes, we can
We ll write a function which takes one date parameter and so instedof getting one appoinments we can get the appoinments of that perticular date.