Search code examples
outlookoutlook-addinoffice-addinsoutlook-web-addinsmicrosoft-graph-calendar

Outlook Office context saveasync callback problem for new appointment


I have created a outlook addin which opens in create new appointment page. Here i am opening new appointment page and calling the below function to sync content appointment page.When i open appointment page for first time i am not getting any callback from saveasync method. it is taking so much time. If i close and open my app again and do the same then i am getting callback.

Office.context.mailbox.subject.setAsync('subject');
Office.context.mailbox.body.setAsync('sample body');
Office.context.mailbox.item.saveAsync(
function callback(result) {
   // Process the result.
});

Solution

  • You should nest your calls since they are all async.

    Office.context.mailbox.subject.setAsync
    (
        "subject",
        function (asyncResult0)
        {
            if (asyncResult0.status === Office.AsyncResultStatus.Succeeded)
            {
                Office.context.mailbox.body.setAsync
                (
                    "sample body",
                    function (asyncResult1)
                    {
                        if (asyncResult1.status === Office.AsyncResultStatus.Succeeded)
                        {
                            Office.context.mailbox.item.saveAsync
                            (
                                function (result)
                                {
                                    // Process the result
                                }
                            );
                        }
                    }
                );
            }
        }
    );