Share via

Developing Outlook Addin: Function addHandlerAsync has invalid parameters

Dominique 0 Reputation points
2024-01-10T12:00:05.54+00:00

Hello,

I am developing an Outlook addin in Javascript using React. I have problems detecting text selection in an email when composing it and when the addin is enabled in the task pane.
My code looks the following:

 Office.context.mailbox.item.addHandlerAsync(
          Office.EventType.ItemChanged,
          function(eventArgs) {
            if (eventArgs.itemType === Office.MailboxEnums.ItemType.Message) {
              if (eventArgs.item.getSelectedDataAsync) {
                eventArgs.item.getSelectedDataAsync(
                  Office.CoercionType.Text,
                  function(result) {
                    if (result.status === Office.AsyncResultStatus.Succeeded) {
                      var selectedText = result.value;
                    }
                  }
                );
              }
            }
          }

I get an error which says" Function addHandlerAsync has invalid parameters". Not sure what is invalid here?
However I tried a lot to get rid of this error and changed

Office.context.mailbox.item.addHandlerAsync

into (removed the item)

Office.context.mailbox.addHandlerAsync

and I did not get the error anymore but it is not working and not recognizing any text selection. I also think the second option is the right way to continue for recognising events in an email when compose.

I also tried to give the permissions in the manifest file but I am not sure what else to change or if that problem is related to that.
I would appreciate some help
Thanks

Microsoft 365 and Office | Development | Other
Outlook | Windows | Classic Outlook for Windows | For business
0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.