'Event handler ItemSend is calling again Office.onReady
I hade defined an event in my manifest
<ExtensionPoint xsi:type="Events">
<Event Type="ItemSend" FunctionExecution="synchronous" FunctionName="itemSendHandler" />
</ExtensionPoint>
And my main.js has something like
window.test1 = 5
Office.onReady((info) => {
if (info.host === Office.HostType.Outlook && !sendEvent) {
// $() is equivalent to $(document).ready() which is deprecated
$(function () {
window.test1 = 20
$('#test_button').on('click', () => { window.test1 = 10 })
// do more stuff
})
}
})
function itemSendHandler (event) {
sendEvent = event
//...
}
I load the Addin and check for window.test1 and is 20 as expected. I click #test_button, check again and now window.test1 is 10 as expected. But when I click the button Send in Outlook and dump window.test1 into Office.context.mailbox.item.notificationMessages now window.test1 is 20 again.
Why is Office.onReady being called again when I click the Send button?
How can I detect that Office.onReady is being called by ItemSend event handler?
Solution 1:[1]
When you say "I load the Addin" does this mean in a Taskpane/ExecuteFunction?
If so, the ItemSend feature does not use the same sandbox/instance as the Taskpane. (In fact all buttons / extensions points do not reuse any web instances). In other words, if you have a Taskpane on one Button, and an ExecuteFunction on another Button, and ItemSend handler. Then they are treated as separate instance, and will all trigger their own onReady.
If you need to communicate information from one instance to another, it is recommended to use the CustomProperties to save information to the item, and then it can be referenced from other add-in instances. https://docs.microsoft.com/en-us/javascript/api/outlook/office.customproperties?view=outlook-js-preview
i.e In your taskpane you could save a custom property test1 = 20. Then in your itemSend handler load custom property to get the value of test1.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Outlook Add-ins Team - MSFT |
