ItemChanged event in outlook - 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.

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.

How to execute JS Code when Outlook is started with Web Add Ins?

I want to make a async request to my server every time a user of my plugin starts outlook (or at least before they open an email).
I have a web Add In with a function file. This file is called whenever a user press a button for this addin. The function file is only loaded after a button (of my plugin) press.
Try this:
// This function is called when Office.js is ready to start your Add-in
Office.initialize = function ()
{
$(document).ready(function ()
{
//call your function here
This is not possible with WebAddIns as the Outlook Add-Ins Teams said in the comments under the question.
One solution is to create a VSTO AddIn and make the request there.

Outlook Add In Recipient Not Being Returned

I'm creating an Outlook Add-in that will take the recipients and check to see if they exists in our database.
When the user clicks on a mailto link on a page it will pop up the Outlook compose window and the recipient will be populated
as such.
Running the Add-in will lead to a nothing being returned from the Office.context.mailbox.item.to.getAsync function.
Office.initialize = function () {
$(document).ready(function () {
Office.context.mailbox.item.to.getAsync(getRecipientFromDB);
});
};
However, the recipient will now look like this:
Retrying the Add-in will now work because the Office.context.mailbox.item.to.getAsync function will actually return a result.
My Outlook version is 16.0.11029.20045.
Has anyone ran into this issue before?
to.getAsync will return every resolved recipient in the "to" field. In the first screenshot, test#test.com is not resolved, so to.getAsync will not return anything. If you open the compose window, wait until recipients resolve, and then run the add-in, to.getAsync will return a result.

uiless action in Outlook add-in with displayDialog()

We are seeing a change in Outlook with one of actions (“Help”) that stopped working on the web client only.
This action simply calls a js that opens a web page in a displayDialog() but it’s uiless in the sense that there’s no pane.
The other action (“Sign”) works ok but it launches a pane that does this.
Both of them work fine on the rich client (at least the version I use).
I wonder if there has been in recent changes in the requirements or the way this works?
We’re not seeing any error messages, just nothing happens after the prompt saying that the add-in is doing something.
We did some initial testing and noticed that in chrome the dialog will sometimes appear briefly. Could you confirm that you are calling event.completed() in the eventhandler of EventType.DialogEventReceived? event.completed() must be called in the DialogEventReceived handler otherwise the dialog will be closed prematurely.
Office.context.ui.displayDialogAsync(url, dialogOptions, function(result) {
// In the callback, save the dialog object
dialog = result.value;
// Add an event handler for messages sent via messageParent
dialog.addEventHandler(Microsoft.Office.WebExtension.EventType.DialogMessageReceived, receiveMessage);
// Add an event handler for events from the platform (like closing the dialog, etc.)
dialog.addEventHandler(Microsoft.Office.WebExtension.EventType.DialogEventReceived, dialogClosed);
});

Resources