Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Office.context.mailbox.getSelectedItemsAsync fails with 5001 error in Outlook for MacOS #5244

Open
JamesDerrickHH opened this issue Jan 6, 2025 · 7 comments
Assignees
Labels
Area: Outlook Issue related to Outlook add-ins Needs: attention 👋 Waiting on Microsoft to provide feedback

Comments

@JamesDerrickHH
Copy link

JamesDerrickHH commented Jan 6, 2025

Your Environment

  • Mac, iOS, Office on the web]: Mac
  • Host [Excel, Word, PowerPoint, etc.]: Outlook
  • Office version number: 16.92
  • Operating System: MacOS Sequoia 15.2
  • Browser (if using Office on the web): N/A

Expected behavior

The async method should return the current selected mailbox item, as it does when my Outlook Add-in is run in Outlook for windows or the web version of outlook.

Current behavior

When an email is selected from the message list my add-in returns an error object instead of the message item object

{
error: {
name: "Internal Error",
message: "An internal error has occurred."
code: 5001
}
}

Steps to reproduce

My taskpane add-in is written with react, and uses this code to handle when the email selection is changed

useEffect(() => {
    const handleSelectedItemsChanged = (eventArgs) => {
      console.log('Selected items changed', eventArgs);
      if(Office.context.requirements.isSetSupported('Mailbox','1.13')) {
        Office.context.mailbox.getSelectedItemsAsync(result => {
          console.log(result)
          if(result.status === Office.AsyncResultStatus.Succeeded) {
            const emails: any = result.value
            console.log('Selected Emails', emails)
            if(emails.length === 1 && Office.context.requirements.isSetSupported('Mailbox','1.14')) {
              emails[0].isReply = Office.context.mailbox.item?.inReplyTo ? true : false
            }
            setSelectedEmails(emails)
            if(emails.length === 1 && (emails[0].itemMode === 'Compose' || emails[0].isReply)) {
              setComposeMode(true)
            } else {
              setComposeMode(false)
            }
          }
        })
      }
    };

    // Add the event handler
    if(Office.context.requirements.isSetSupported('Mailbox','1.13')) {
      Office.context.mailbox.addHandlerAsync(
        Office.EventType.SelectedItemsChanged,
        handleSelectedItemsChanged,
        (result) => {
          if (result.status === Office.AsyncResultStatus.Failed) {
            console.error(result.error.message);
          }
        }
      );
    }

    handleSelectedItemsChanged({})

    //Clean up the event handler
    return () => {
      if(Office.context.requirements.isSetSupported('Mailbox','1.13')) {
        Office.context.mailbox.removeHandlerAsync(
          Office.EventType.SelectedItemsChanged,
          { handler: handleSelectedItemsChanged } as Office.AsyncContextOptions,
          (result) => {
            if (result.status === Office.AsyncResultStatus.Failed) {
              console.error(result.error.message);
            }
          }
        );
      }
    };
  }, []);

The console log message on the 6th line of my code snippet is where I'm seeing the error object

Context

I am seeing this issue in a taskpane add-in I have developed that allows you to select destination folders for where you would like an email to be moved to. This add-in works perfectly on all current versions of outlook apart from Outlook for MacOS, because it does not know what the current selected email is.
Because the mailbox async item is unable to return the item object, then my add-in essentially doesn't work, without a selected email or emails, I have no item id to pass to graph to move the email.
I am semi-certain that it did work before Christmas, but I do also remember times before that that it also exhibited the same behaviour as mentioned in this issue.

Any help or advice would be greatly appreciated

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: triage 🔍 New issue, needs PM on rotation to triage ASAP label Jan 6, 2025
Copy link

github-actions bot commented Jan 6, 2025

Here are some similar issues that might help you. Please check if they can solve your problem.


Possible solution (Extracted from existing issue, might be incorrect; please verify carefully)

Solution 1:

It sounds like you might have an issue with the ItemChanged event. You will need to register the event handler for the ItemChanged event when you call Office.initialize, so the add-in is notified when the item is changed. A sample for doing this can be found here.

Reference:

Solution 2:

To anyone that is facing something similar in Outlook 2016, don't try to handle/convert the getAsync callback into Promises. Even if you added polyfills for promises for IE11. It will work for Outlook 2019 onwards but will raise the code 5010 in Outlook 2016.

Reference:

@JamesDerrickHH
Copy link
Author

Regarding the possible solutions, I do not think there is a problem with my ItemChanged event as it is successfully triggered every time I change which email is selected, I just get an error object instead of the mailbox item object.
And for me it is happening regardless of whether the emails are grouped by conversation or not

@exextoc exextoc added Needs: attention 👋 Waiting on Microsoft to provide feedback Area: Outlook Issue related to Outlook add-ins and removed Needs: triage 🔍 New issue, needs PM on rotation to triage ASAP Similar-Issue Possible-Solution labels Jan 6, 2025
@exextoc exextoc self-assigned this Jan 6, 2025
@JamesDerrickHH
Copy link
Author

JamesDerrickHH commented Jan 6, 2025

To add to this, I have just discovered that if I have 2 email accounts set up in my Mac Outlook client, and select an email from the All Accounts inbox then it works (for single emails only).
It does not work for multiple emails selected (even though the add-in does work for multiple emails on the web or in Windows) .

UPDATE: spoke too soon, it only works in selecting the first email when the taskpane is loaded

@whoanuragverma
Copy link

We are not able to repro the bug you mentioned with the snippet you provided. Can you please create a sample addin which can reproduce this bug and share the manifest and the addin in a private repository and provide access to @exextoc.

It will be helpful if you can share a video of the bug too.

@whoanuragverma whoanuragverma added Needs: author feedback Waiting for author (creator) of Issue to provide more info and removed Needs: attention 👋 Waiting on Microsoft to provide feedback labels Jan 7, 2025
@JamesDerrickHH
Copy link
Author

I've created a test add-in but now the issue isn't presenting itself on the "live" add-in or the new test one
Will test again tomorrow and add a link to the repo if the issue resurfaces

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: attention 👋 Waiting on Microsoft to provide feedback and removed Needs: author feedback Waiting for author (creator) of Issue to provide more info labels Jan 8, 2025
@JamesDerrickHH
Copy link
Author

I have found a decent test case
It looks like the getSelectedItemsAsync method works fine when you first load Outlook
Then if you close it, via the red cross, it doesn't really close, and still shows that the application is running in the dock
re-open the application from the dock and then the method no longer works (gives the error I mentioned earlier)
I have added @exextoc to my repository
And I'll supply some videos in a few minutes

@JamesDerrickHH
Copy link
Author

This is the method working with console logs
https://github.com/user-attachments/assets/9a7a2c86-9792-4406-9016-4b71efd2ffc5

This is the method not working with console logs
https://github.com/user-attachments/assets/9864f6a7-afbb-4c48-9dde-45e9385bad50

And this is the test case with open, closing and re-opening Outlook
https://github.com/user-attachments/assets/7f8dd620-d5bc-480f-8f6e-32194510e79f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Outlook Issue related to Outlook add-ins Needs: attention 👋 Waiting on Microsoft to provide feedback
Projects
None yet
Development

No branches or pull requests

3 participants