none
EWS - Querying deleted items and getting old information back RRS feed

  • Question

  •  

    I'm writing a script that is supposed to query a calendar and get back all changed and deleted items. However, whenever an item gets deleted, I cannot seem to get it's information back.


    What I am currently doing is :

     

    public void printEvents() {
    		try {
    			GetEventsResults events = subscription.getEvents();
    			if(events.getAllEvents().isEmpty()) {
    				System.out.println("Nothing happened, or at least so it seems : " + subscription.getEvents().getAllEvents().toString());
    			}
    			else {
    				for (ItemEvent itemEvent : events.getItemEvents()) {
    					if ((itemEvent.getEventType() == EventType.Created)
    							|| (itemEvent.getEventType() == EventType.Modified)
    							|| (itemEvent.getEventType() == EventType.Deleted)) {
    					
    						this.sendMail(itemEvent);
    							
    					} else
    						System.out.println("Something else happened : " + itemEvent.getEventType());
    				}
    			}
    
    		} catch (Exception e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    	}
    

     

    However, whenever an element gets "deleted" the server actually tells me it is "modified". When I then query the item, it tells me "The specified object was not found in the store"... How would I be able to actually know an item is deleted and then get it's information ?

    I would like to do the same for modified events (how do I get back the OLD information of the event -> before it got changed).


    Thanks a lot for the help,

    Joshua

    If needed, here is the method used to go through the event :

    public void sendMail(ItemEvent itemEvent) {
    		String subject = "An event was " + itemEvent.getEventType();
    		String message = "";
    		Appointment appointment;
    		
    		try {
    			appointment = Appointment.bind(service, itemEvent.getItemId());
    			
    			System.out.println("Successfully bound to the item");
    			if (itemEvent.getEventType() == EventType.Created) {
    				message = "An event was created in the Calendar, these are the details : <br>\n"
    						+ "Event subject : "
    						+ appointment.getSubject()
    						+ "<br>\n"
    						+ "Created on : "
    						+ appointment.getDateTimeCreated()
    						+ "<br>\n"
    						+ "Created by : "
    						+ appointment.getLastModifiedName()
    						+ "<br>\n"
    						+ "Start of appointment : "
    						+ appointment.getStart()
    						+ "<br>\n"
    						+ "End of appointment : " + appointment.getEnd();
    			} else if (itemEvent.getEventType() == EventType.Modified) {
    				Iterator<OccurrenceInfo> it = appointment.getModifiedOccurrences().iterator();
    				
    				if(it.hasNext()) {
    					System.out.println(it.next().toString());
    				}
    				message = "An event was modified in the Calendar, these are the details : <br>\n"
    						+ "Event subject : "
    						+ appointment.getSubject()
    						+ "<br>\n"
    						+ "Modified on : "
    						+ appointment.getLastModifiedTime()
    						+ "<br>\n"
    						+ "Modified by : "
    						+ appointment.getLastModifiedName()
    						+ "<br>\n"
    						+ "Start : "
    						+ appointment.getStart()
    						+ "<br>\n" + "End : " + appointment.getEnd();
    			} else
    				System.out.println("Something else");
    		} catch (Exception e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    
    		/*JFrame myFrame = new JFrame();
    		JTextArea tarea = new JTextArea();
    		tarea.setText(message);
    		tarea.setColumns(50);
    		tarea.setRows(10);
    		myFrame.getContentPane().add(tarea);
    		myFrame.pack();
    		myFrame.setVisible(true);*/ 
    		
    		System.out.println(subject + "--\n" + message);
    		// this.sendMail(this.mailingList, subject, message);
    	}

    Tuesday, March 29, 2011 5:15 PM

All replies

  • Great question,

    Did you ever find an answer?

    -Johonas

    Wednesday, October 26, 2011 7:50 PM
  • Hi,

    if an item is actually deleted, you wont be able to get its information. This is however only when the EventType is 'Deleted'.

    In your case it might be, that the item has been just moved to the folder containing the deleted items. You should get the EventType 'Moved' in this case.

    The itemEvent contains a property called 'OldItemId'. With the value stored in this property you should be able to actually get the appointment.

    Kind regards,

    Kai Hartmann

    Friday, May 17, 2013 12:48 PM