Share via

Event whenever outlook addin panel is closed

Afroz Alam 1 Reputation point Microsoft Employee
2023-01-13T04:09:55.6933333+00:00

Is there

Is there any event in Outlook add-in API that we can tap into to know whenever the add-in panel is getting closed (either by explicitly clicking on a close button from the add-in panel or whenever the user moves from one email to another )?

I haven't found something in the add-in documentation.

Microsoft 365 and Office | Development | Other
Outlook | Windows | Classic Outlook for Windows | For business
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Andrew Dello Stritto 85 Reputation points Microsoft External Staff
    2023-01-13T04:26:04.4133333+00:00

    Yes, there is an event in the Outlook add-in API that allows you to detect when the add-in panel is closed. The event is called Office.EventType.DialogEvent.DialogClosed. You can use this event to attach a callback function that is invoked whenever the add-in panel is closed. This callback function allows you to perform any necessary actions, such as saving data or resetting the state of your add-in, before the panel is closed.

    You can register the event by calling the Office.context.ui.addEventHandler method, like this:

    Copy code Office.context.ui.addEventHandler(Office.EventType.DialogEvent.DialogClosed, myCallbackFunction); In the callback function, you can check the result property of the event object, which will be 'cancel' if the user closed the dialog by clicking the close button, or 'success' if the user completed the action.

    Copy code function myCallbackFunction(event) { if (event.result === 'cancel') { // Perform actions when user closes the dialog explicitly } } You can also use the Office.EventType.ItemChanged event, this event triggers whenever the user navigates to another email or calendar item, you can use this event to detect when the user leaves the current email and save any changes before the add-in is closed.

    Copy code Office.context.mailbox.addHandlerAsync(Office.EventType.ItemChanged, myCallbackFunction); Please note that this event only works when the add-in is running in an email context (i.e. when the add-in is open in an open email or calendar item)


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.