none
Problem on resetting mail item categories in Outlook Web Add-in working with shared mailbox RRS feed

  • Question

  • I am working on Outlook Web Add-in using in a shared mailbox. Custom properties are used to store the additional mail information and such information is highlighted in mail item categories.<o:p></o:p>

    Below is the sample coding:

        function setMailInfo() {
            Office.context.mailbox.item.loadCustomPropertiesAsync(function (asyncResult) {
                if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                    console.error("loadCustomPropertiesAsync(1): " + asyncResult.error.message);
                } else {
                    var customProp = asyncResult.value;
                    customProp.set("MailStatus", "P");
                    customProp.set("MailUpdatedByUserName", "User 01");
                    customProp.saveAsync(function (asyncResult) {
                        if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                            console.error("customProp.saveAsync: " + asyncResult.error.message);
                        } else {
                            Office.context.mailbox.item.loadCustomPropertiesAsync(function (asyncResult) {
                                if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                                    console.error("loadCustomPropertiesAsync(2): " + asyncResult.error.message);
                                } else {
                                    var customPropLoaded = asyncResult.value;
                                    console.info("Call setItemUpdatedByCategoriesAsync");
                                    setItemUpdatedByCategoriesAsync(customPropLoaded, function (asyncResult) {
                                        if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                                            console.info("-- end of setMailInfo --");
                                        } else {
                                            console.info("Call setItemMailStatusCategoriesAsync");
                                            setItemMailStatusCategoriesAsync(customPropLoaded, function (asyncResult) {
                                                console.info("-- end of setMailInfo --");
                                            });
                                        }
                                    });
                                }
                            });
                        }
                    });
                }
            });
        }
        function setItemMailStatusCategoriesAsync(customProp, callbackFunc) {
            var mailStatus = customProp.get("MailStatus");
            var mailCategoriesToRemove = ["@New", "@Completed"];  // Assume "@New" or "@Completed" category is set to mail item
            var mailCategoriesToAdd = [(mailStatus === "P") ? "@In Progress" : "@New"];  // Assume "@In Progress" is already defined in mailbox master category
            Office.context.mailbox.item.categories.removeAsync(mailCategoriesToRemove, function (asyncResult) {
                if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                    console.error("categories.removeAsync: " + asyncResult.error.message);
                    callbackFunc(asyncResult);
                } else {
                    Office.context.mailbox.item.categories.addAsync(mailCategoriesToAdd, function (asyncResult) {
                        if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                            console.error("categories.addAsync: " + asyncResult.error.message);
                        } else {
                            callbackFunc(asyncResult);
                        }
                    });
                }
            });
        }
        function setItemUpdatedByCategoriesAsync(customProp, callbackFunc) {
            var updatedBy = customProp.get("MailUpdatedByUserName");
            var mailCategoriesToRemove = ["#User 02"];  // Assume "#User 02" category is set before
            var mailCategoriesToAdd = ["#" + updatedBy];  // Assume "#User 01" is already defined in mailbox master category
            Office.context.mailbox.item.categories.removeAsync(mailCategoriesToRemove, function (asyncResult) {
                if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                    console.error("categories.removeAsync: " + asyncResult.error.message);
                    callbackFunc(asyncResult);
                } else {
                    Office.context.mailbox.item.categories.addAsync(mailCategoriesToAdd, function (asyncResult) {
                        if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                            console.error("categories.addAsync: " + asyncResult.error.message);
                        } else {
                            callbackFunc(asyncResult);
                        }
                    });
                }
            });
        }

    When the above "setMailInfo()" function is called by clicking a button in the task pane, I expected that the new categories "@In Progress" and "#User 01" are set and the original categories "@New" / "@Completed" and "#User 02" are cleared. However, the actual result is not that case. Sometimes,

    • The original categories are removed but only one of the new categories could be added; OR
    • The original categories are removed and the new categories could be added but then one of removed categories appeared again; OR
    • On screen, the original categories are removed and the new categories are added. After refresh the web-page, some of new categories disappeared.

    No error was captured in console. And, there is no problem for user's own mailbox.

    What is the correct way to add / remove the mail item categories under shared mailbox?

    Wednesday, December 4, 2019 9:02 AM