Search code examples
javascriptoutlook-addinoffice-jsoutlook-web-addins

displayNewMessageForm does not work when used inside Outlook reply


I have an Outlook add-in that is available on compose and read mode. If user goes through the compose add-in , at the end, some content created by user gets added to the email body. You can only see the compose add-in when you click 'NEW'.

On Read scenario, I have 3 options on my add-in commands dropdown - New, Reply, ReplyAll. User goes through the add-in, same as Compose mode, but at the end I use displayNewMessageForm, displayReplyForm and displayReplyAllForm to create a new email depending on action chosen.

So far it works fine. Here comes the problem:

When user opens an email and uses Outlook's reply/replyall/forward actions, my add-in shows up on the new window. (Arrow just shows my add-in icon) enter image description here Now, user clicks the add-in completes the necessary steps and at the end I use displayNewMessageForm,displayReplyForm and displayReplyAllForm again to create a new email. But at this point, above API calls are failing.

Error Message: Office.context.mailbox.displayNewMessageForm is not a function. Although I don't think it is code related, here is the code for those API calls.

Formdata and parameters are properly formed and it works fine on the read mode.

 if (selectedEmailType == 'New' || selectedEmailType == 'NewEmail') {
                                                Office.context.mailbox.displayNewMessageForm(parameters);
                                        }
                                        if (selectedEmailType == 'ReplyEmail') {
                                                Office.context.mailbox.item.displayReplyForm(
                                                        formdata,
                                                        function(asyncResult) {
                                                                console.log(asyncResult.value);
                                                                Office.context.ui.closeContainer();
                                                        }
                                                );
                                        } else if ((selectedEmailType == 'ReplyAllEmail')) {
                                                Office.context.mailbox.item.displayReplyAllForm(
                                                        formdata,
                                                        function(asyncResult) {
                                                                console.log(asyncResult.value);
                                                                Office.context.ui.closeContainer();
                                                        }
                                                );
                                        }

Solution

  • If I understand your problem correctly, you're trying to use displayReplyForm and the other mentioned APIs while an add-in is running while composing an email. These APIs can only be used in Read Mode and will not be available in Compose Mode. You can find the documentation here. The "Applicable Outlook Mode" for these API's is "Read".