none
Unable to get Tasks using EWS API RRS feed

  • Question

  • Hi,

    I am trying the following Java code to get the tasks from an Exchange Server, but instead I am getting an error. I am using the latest jar. (ews-java-api-2.0.jar)

    public class ExchangeTest {
    
    	public static void main(String[] args) {
    	    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
    	    ExchangeCredentials credentials = new WebCredentials(<username>, <pswd>);
    	    service.setCredentials(credentials);
    
    	    try {
    			service.setUrl(new URI(<serverURL>));
    		} catch (URISyntaxException e) {
    			e.printStackTrace();
    		}
    	    
    	    ItemView view = new ItemView(50);
    	    FindItemsResults<Item> findResults;
            SearchFilter.SearchFilterCollection filterCollection = new SearchFilter.SearchFilterCollection();
            
            SearchFilter.IsEqualTo searchFilter = new SearchFilter.IsEqualTo();
            searchFilter.setPropertyDefinition(TaskSchema.Status);
            searchFilter.setValue(TaskStatus.Completed);
            filterCollection.add(searchFilter);
            
            try {
    			//findResults = service.findItems(WellKnownFolderName.Tasks, view);					//This API call works fine
    			findResults = service.findItems(WellKnownFolderName.Tasks, filterCollection, view);			//This API call throws the error
    			for (Item item : findResults.getItems()){
    				System.out.println(item);
    			}
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    
    	}
    
    }

    The error that is being thrown is:

    microsoft.exchange.webservices.data.core.exception.service.remote.ServiceResponseException: The specified value is invalid for property.
    	at microsoft.exchange.webservices.data.core.response.ServiceResponse.internalThrowIfNecessary(ServiceResponse.java:278)
    	at microsoft.exchange.webservices.data.core.response.ServiceResponse.throwIfNecessary(ServiceResponse.java:267)
    	at microsoft.exchange.webservices.data.core.request.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:165)
    	at microsoft.exchange.webservices.data.core.ExchangeService.findItems(ExchangeService.java:985)
    	at microsoft.exchange.webservices.data.core.ExchangeService.findItems(ExchangeService.java:1028)
    	at microsoft.exchange.webservices.data.core.ExchangeService.findItems(ExchangeService.java:1088)
    	at ExchangeTest.main(ExchangeTest.java:52)

    I have tried with version 1.1.5 and was getting the same error. It is also worth noting that the same code works in WebDAV API for Exchange Server 2007.

    I would be grateful for any guidance.

    Friday, May 6, 2016 11:44 AM

Answers

  • Exchange doesn't support searching using particular Strongly type properties like Task.Status, what you should use is the Extended property representation for that particular property which for TaskStatus is PidLidTaskStatus https://msdn.microsoft.com/en-us/library/ee159828(v=exchg.80).aspx

    So with a SearchFilter something like (// 0x1 = Inprogress Tasks)

                ExtendedPropertyDefinition PidLidTaskStatus = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Task, 0x8101, MapiPropertyType.Integer);
                SearchFilter TaskStatusSearchFilter = new SearchFilter.IsEqualTo(PidLidTaskStatus, 1);
    Cheers
    Glen

    Monday, May 9, 2016 4:36 AM

All replies

  • Exchange doesn't support searching using particular Strongly type properties like Task.Status, what you should use is the Extended property representation for that particular property which for TaskStatus is PidLidTaskStatus https://msdn.microsoft.com/en-us/library/ee159828(v=exchg.80).aspx

    So with a SearchFilter something like (// 0x1 = Inprogress Tasks)

                ExtendedPropertyDefinition PidLidTaskStatus = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Task, 0x8101, MapiPropertyType.Integer);
                SearchFilter TaskStatusSearchFilter = new SearchFilter.IsEqualTo(PidLidTaskStatus, 1);
    Cheers
    Glen

    Monday, May 9, 2016 4:36 AM
  • Hi Glen,

    Can you also provide reference needed for creating the ExtendedPropertyDefinition which can be used for creating filters for other properties. (Eg. sensitivity, organizer, etc).

    Apparently, its not that easy to find it using a search engine.

    Thanks

    Nikhil

    Thursday, May 19, 2016 10:30 AM