OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
670 stars 96 forks source link

contextData in Office.SmartAlertsEventCompletedOptions #3841

Open krzysztof-plutoflume opened 10 months ago

krzysztof-plutoflume commented 10 months ago

I've got a question regarding the contextData member of the Office.SmartAlertsEventCompletedOptions interface:

The contextData option specifies any JSON data you want to pass to the add-in when the Don't Send button is selected. If you include this option, you must also set the commandId option. Otherwise, the JSON data is ignored.

How does the add-in receive the context data passed through this option?


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

alison-mk commented 10 months ago

Hi @krzysztof-plutoflume, thanks for submitting this Outlook question. @samantharamon Could you take a look?

samantharamon commented 10 months ago

Hi @krzysztof-plutoflume,

Thanks for reaching out. In the file containing your task pane code, you'll need to call Office.context.mailbox.item.getInitializationContextAsync to retrieve the context data you passed to your event handler.

Here's a sample implementation.

Event handler code

...
event.completed(
  {
    allowEvent: false,
    cancelLabel: "Add a location",
    commandId: "msgComposeOpenPaneButton",
    contextData: JSON.stringify({ a: "aValue", b: "bValue" }),
    errorMessage: "Don't forget to add a meeting location.",
    sendModeOverride: Office.MailboxEnums.SendModeOverride.PromptUser
  }
);

Task pane code

...
Office.context.mailbox.item.getInitializationContextAsync((asyncResult) => {
  if (asyncResult.status === Office.AsyncResultStatus.Failed) {
    console.log(asyncResult.error.message);
    return;
  }

  const contextData = JSON.parse(asyncResult.value);
  console.log(contextData.a);
});
...

I realize that this isn't documented, so I apologize for the inconvenience. I'll get this included in our documentation.

krzysztof-plutoflume commented 10 months ago

Thanks for your explanation, very clear.

If the task pane with the given commandId is already open when the user clicks Don't Send on the Smart Alerts dialog, is the task pane supposed to receive an updated initialisation context (with the value as set for contextData in Office.SmartAlertsEventCompletedOptions)?

At the moment, the initialisation context doesn't seem to be updated, and an already opened task pane isn't reloaded when the user clicks Don't Send.

Is there a reliable way to signal to the task pane that the user clicked Don't Send, so that we can update the contents of the task pane to explain to the user why the email was blocked from sending?

samantharamon commented 10 months ago

That's a great question. I'm also able to replicate the behavior you're seeing. Let me follow up on this with the team.

samantharamon commented 9 months ago

Thanks for your patience, @krzysztof-plutoflume. I've confirmed that the contextData value doesn't currently get updated in the task pane if the pane is already open. I'm assigning this to @besiler to investigate it further.

As a workaround, you could use a SessionData object to store data that can be accessed from the task pane. For more information, see Office.SessionData.

alexm-plutoflume commented 1 month ago

@samantharamon @exextoc,

Hi both, I wanted to re-raise this issue or at least see what you recommend. In our OnSend event, we are setting some SessionData that we want displayed in the taskpane when the user clicks "don't send".

In New Outlook for Windows, OWA, Outlook for Mac, and Classic Windows inline messages only - if the task pane is already open, the user tries to send the email again and is blocked again, the task pane is refreshed automatically/reinitialized when they click "Don't send". This works great., our new SessionData is read and the taskpane accurately reflects what it should.

For Classic Windows, the task pane does not get refreshed automatically for some reason when the email is popped out. I'm wondering if this is a bug? If not, what is your recommendation to ensure the task pane is always using the most updated data from the OnSend event? Do we need to be constantly polling/refreshing the task pane in the background and checking for updated SessionData?

ztcdsb commented 3 weeks ago

Thanks for reporting this issue. It has been put on our backlog. We unfortunately have no timelines to share at this point

Internal tracking id: Office: [9148448]