Outlook 2016 Addin VSTO Catch new calendar event - outlook

I have a Add-in for Outlook 2016 and I catch when a new calendar event is created by code:
inspectors = this.Application.Inspectors;
inspectors.NewInspector +=
new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);
This is working fine if the user:
1. Click on [New Appointment] in the ribbon
2. Right click on the calendar and choose [New Appointment]
3. Doubleclick in the calendar
But if the user create a new calendar event by entering a text directly in the calendar the event is not raised.
How do I catch this?

In that case no Inspector window is created, so you will not trap into the NewInspector event. Instead, you can handle the ItemAdd event of the Items class which is fired when one or more items are added to the specified collection. Note, this event does not run when a large number of items are added to the folder at once.

Related

Outlook Add-in that just directs to a website

I want to program a simple Outlook add-in that opens a browser and take the user to a specific site.
I've had a look at using Yeoman, but this add-in opens a task pane where I'm just looking to take that single actions.
Is there a simple way to do this?
EDIT:
I managed to get this done, but I not have the following issue: I have a single button (via Yeoman's generator) that when clicked executes the following:
function action(event) {
const message = {
type: Office.MailboxEnums.ItemNotificationMessageType.InformationalMessage,
message: "Window opened.",
icon: "Icon.80x80",
persistent: true,
};
// Show a notification message
window.open("https://myurl.com");
Office.context.mailbox.item.notificationMessages.replaceAsync("action", message);
// Be sure to indicate when the add-in command function is complete
event.completed();
}
I get the following error in Outlook itself:
We deployed the app using the MS 365 admin center, but I'm not sure if there is something additional that I need to do in this case to run the webserver?
There is an Office.js API that will open a browser window:
Office.ui.openBrowserWindow( -- URL string here -- );
This will cause the computers default browser to open to the specified URL. You could have a button in the task pane whose handlers calls this method. Alternatively, you could have a custom button on the ribbon that calls a FunctionFile that calls this method.
If you want to display any web site to the user as a result of the button click or some action on the pane, try doing window.open('https://yoursite.com'). This should work if the domain is whitelisted in your manifest. For example:
function redirectFunction() {
window.open("https://othersite.com")
//window.location.href = "https://othersite.com";
}

Outlook Add-In: AppointmentTimeChanged Event not getting triggered on changing the time of the event

I am trying to listen for any change in timing of the appointment through my Add-In. Here is the code where I am adding the handler.
Office.onReady(function() {
mailboxItem = Office.context.mailbox.item;
console.log("Added event handler");
mailboxItem.addHandlerAsync(Office.EventType.AppointmentTimeChanged, args =>
console.log("AppointmentTimeChanged")
),
args => {
console.log("Listening");
};
});
This however is not working for me.
AppointmentTimeChanged event listener works only till the lifecycle of the add-in. If you are using UI-less add-in functions you will not receive notifications beyond your call to event.completed().
To listen to changes beyond that you will have to listen to change using graph web hooks (https://learn.microsoft.com/en-us/graph/webhooks). This subscription from your backend service will enable you to be notified for event changes even from other clients.
But there is a catch to it, Outlook for MAC does not provide way to listen these changes till the event is sent out. To work around this problem you can use custom properties and listener to changes with these properties. Here is the doc explaining it: https://learn.microsoft.com/en-us/outlook/troubleshoot/calendars/cannot-save-meeting-as-draft-in-outlook-for-mac.

ItemChanged event in outlook

Hi I am building an outlook addin, I want to know if there is way to handle the ItemChange event, I know we can use it by pinning the taskpane, isn’t there any other way??
Currently ItemChanged event can only be used in case of pinned add-in. We track Outlook add-in feature requests on our user-voice page. Please add your request there. Feature requests on user-voice are considered when we go through our planning process.
You need to use the addHandlerAsync(eventType, handler, [options], [callback]) method to subscribe to the ItemChange event. Here is what MSDN states:
Currently the only supported event type is Office.EventType.ItemChanged, which is invoked when the user selects a new item. This event is used by add-ins that implement a pinnable task pane, and allows the add-in to refresh the task pane UI based on the currently selected item.
Office.initialize = function (reason) {
$(document).ready(function () {
Office.context.mailbox.addHandlerAsync(Office.EventType.ItemChanged, loadNewItem, function (result) {
if (result.status === Office.AsyncResultStatus.Failed) {
// Handle error.
}
});
});
};
function loadNewItem(eventArgs) {
// Load the properties of the newly selected item.
loadProps(Office.context.mailbox.item);
};
Also, you may find the following discussion helpful - Outlook Add-In API does not fire the ItemChange event consistently on Firefox/Chrome. ItemChange fires when the item actually changes, but not when you simply change the selection.

What can I do to get informed for every new inspector

I need to subsribe to events for every new inspector that will be opend.
And also want to invalidate the ribbon on every new Inspector.
Ther is an event that will be called for every new inspector:
Globals.ThisAddIn.Inspectors.NewInspector += (sender, explorer) => ribbon.Invalidate();
However this event will not be called when a new inspector is opend via the send to -> Mail recipient from the windowsd explorer.
Another aproach was to register to the UI events in the ribbon. But those will also not called every time a new window is opend.
Is there is any way to reliable get notified for every new inspector?
NewInspector does not fire on purpose when a new message is created using Simple MAPI or fro ma mailto link.
You can have a timer that wakes up every couple seconds and checks if the Application.Inspectors collection has any new inspectors you have not processed yet.

Windows API - Window registration event

Is there any event function in WinAPI that allows catching window registration moment by it's class name? For exaple trigger event when application starts or create new window.
I've found EVENT_OBJECT_CREATE but it doesn't seem to catch proper event. Any ideas?

Resources