I am using an EWSJavaAPI for creating task in Exchange Server but i am not getting any reference to fetch task using the same api. Below is my code add task:
Task t=new Task(service);
t.setSubject("Task to test in JAVA");
t.setBody(MessageBody.getMessageBodyFromText("Test body from JAVA"));
t.setStartDate(startTime);
t.setDueDate(endTime);
t.save();
And i tried below code to fetch task but this is not working :
//Create the extended property definition.
ExtendedPropertyDefinition taskCompleteProp = new
ExtendedPropertyDefinition(DefaultExtendedPropertySet.Task, 0x0000811C,
MapiPropertyType.Boolean);
//Create the search filter.
SearchFilter.IsEqualTo filter = new
SearchFilter.IsEqualTo(taskCompleteProp, false);
//Get the tasks.
FindItemsResults<Item> tasks =
service.findItems(WellKnownFolderName.Tasks, filter, new ItemView(50));
for(Item task:tasks){
System.out.println(task.getSubject());
System.out.println(task.getBody());// getting error at this line
System.out.println(task.getReminderMinutesBeforeStart());
System.out.println(task.getReminderDueBy());
System.out.println("=======================");
}
error at task.getBody(); microsoft.exchange.webservices.data.ServiceObjectPropertyException: You must load or assign this property before you can read its value. at microsoft.exchange.webservices.data.PropertyBag.getPropertyValueOrException(Unknown Source) at microsoft.exchange.webservices.data.PropertyBag.getObjectFromPropertyDefinition(Unknown Source) at microsoft.exchange.webservices.data.Item.getBody(Unknown Source) at MSExchangeEmailService.readTask(MSExchangeEmailService.java:146) at MSExchangeEmailService.main(MSExchangeEmailService.java:224)
Please help, is this right approach to fetch task??
You need to load the Task first.
Add task.load()
before your for
loop.