Search code examples
outlookoffice-jsoutlook-addinoffice-addinsoutlook-web-addins

Officejs: Can an outlook action trigger the taskpane


I have a two fold questions.

  1. Do actions have click events? I have a simple action that looks like the following: Addin I want to run some typescript code if a user clicks on that Action, is that possible? Are there event handlers for those actions?

  2. From that click can I open the taskpane that is part of my addin? I have tried using Office.addin.showAsTaskpane() but I am not having any luck having that trigger the taskpane. I have been following this issue on github but even so I have not successfully been able to open my taskpane any other way than clicking the ribbon button for toggling the taskpane.

Github Issue

I have tried moving the Office.addin.ShowAsTaskpane() around to several areas of my commands.ts. I have tried in the onRready() as well as before and after my event.complete() Full code for my commands.ts is below:

Office.onReady(() => {
  Office.addin.showAsTaskpane().then();
});

/**
 * Shows a notification when the add-in command is executed.
 * @param event
 */
function action(event: Office.AddinCommands.Event) {
  const message: Office.NotificationMessageDetails = {
    type: Office.MailboxEnums.ItemNotificationMessageType.InformationalMessage,
    message: "Performed action. - Click",
    icon: "Icon.80x80",
    persistent: true,
  };
  // Show a notification message
  Office.context.mailbox.item.notificationMessages.replaceAsync("action", message);

  // Be sure to indicate when the add-in command function is complete
  event.completed();
  Office.addin.showAsTaskpane().then();
}

function getGlobal() {
  return typeof self !== "undefined"
    ? self
    : typeof window !== "undefined"
    ? window
    : typeof global !== "undefined"
    ? global
    : undefined;
}

const g = getGlobal() as any;

// The add-in command functions need to be available in global scope
g.action = action;

Solution

  • It looks like what you are looking for is an InsightMessage type of notification. See https://learn.microsoft.com/en-us/javascript/api/outlook/office.notificationmessageaction?view=outlook-js-preview