如何在 Outlook JS Addin 中触发 ItemSend 事件后进行 console.log
我在处理 ItemSend 事件时遇到了真正的问题,因为 MS Outlook 插件提供了 yo 生成器,它使用 webpack 来捆绑代码,而不是暴露到全局范围,然后是事件的必要功能。
我在清单中有正确的 XML
<ExtensionPoint xsi:type="Events">
<Event Type="ItemSend" FunctionExecution="synchronous" FunctionName="itemSendHandler" />
</ExtensionPoint>
并且 itemSendHandler
是全局的,我的 main.js 是
import { updateEventMetadataToServer, getUserCktId } from './cktApi.js'
import { initializeForm, fetchEventDataFromOutlook, fetchEventDataFromServer, setMsgOnFormConsole } from './form.js'
import { storeEventMetadata, loadEventMetadata, loadCustomProperty } from './outlookApi.js'
window.itemSendHandler = itemSendHandler
test1 = 1 // for debug
function itemSendHandler (event) {
fetchDataFromOutlookAndSubmitOrUpdateEventToCkt((err) => {
if (err) {
Office.context.mailbox.item.notificationMessages.replaceAsync('NoSend', { type: 'errorMessage', message: err.message })
setTimeout(() => { event.completed({ allowEvent: false }) }, 3000)
} else {
const message = {
type: Office.MailboxEnums.ItemNotificationMessageType.InformationalMessage,
message: 'Event submitted/updated to CKT' + test1,
icon: 'Icon.80x80',
persistent: true
}
Office.context.mailbox.item.notificationMessages.replaceAsync('action', message)
setTimeout(() => { event.completed({ allowEvent: true }) }, 10000)
}
})
}
function fetchDataFromOutlookAndSubmitOrUpdateEventToCkt (_callback) {
const callback = (err) => {
if (typeof _callback === 'function') {
_callback(err)
}
}
fetchEventDataFromOutlook((err) => {
if (err) {
console.error('There was some error fetching data from Outlook:', err)
callback(Error('There was some error fetching data from Outlook to CKT Addin'))
} else {
console.success('Data fetched from Outlook assigned to form')
test1 = 20
loadEventMetadata((metadata) => {
console.log('METADATA loded from Outlook: ', metadata)
test1 = JSON.stringify(metadata) + ''
submitUpdateEvent(metadata, (err) => {
if (err) {
console.error('There was an error on submitUpdateEvent', err)
callback(Error('There was some error submitting/updating the event to CKT server'))
} else {
console.success('Data submited/updated to server')
callback()
}
})
})
}
})
}
- 知道如何在单击“发送”按钮后在 Edge/webview2 DEV 控制台中进行 console.log 吗?我无法简单地进行调试,因为单击“发送”按钮后,没有显示 console.log。我正在安慰
Office.MailboxEnums.ItemNotificationMessageType.InformationalMessage
上的调试,这很奇怪 - 知道为什么
loadEventMetadata
在正常情况下获取metadata
但失败itemSend 何时被触发?
I am having really problems dealing with ItemSend event, due to yo generator provided by MS Outlook addins which uses webpack to bundle the code, not exposing to global scope then the necessary functions for the event.
I have the correct XML in the manifest
<ExtensionPoint xsi:type="Events">
<Event Type="ItemSend" FunctionExecution="synchronous" FunctionName="itemSendHandler" />
</ExtensionPoint>
And itemSendHandler
is global, my main.js is
import { updateEventMetadataToServer, getUserCktId } from './cktApi.js'
import { initializeForm, fetchEventDataFromOutlook, fetchEventDataFromServer, setMsgOnFormConsole } from './form.js'
import { storeEventMetadata, loadEventMetadata, loadCustomProperty } from './outlookApi.js'
window.itemSendHandler = itemSendHandler
test1 = 1 // for debug
function itemSendHandler (event) {
fetchDataFromOutlookAndSubmitOrUpdateEventToCkt((err) => {
if (err) {
Office.context.mailbox.item.notificationMessages.replaceAsync('NoSend', { type: 'errorMessage', message: err.message })
setTimeout(() => { event.completed({ allowEvent: false }) }, 3000)
} else {
const message = {
type: Office.MailboxEnums.ItemNotificationMessageType.InformationalMessage,
message: 'Event submitted/updated to CKT' + test1,
icon: 'Icon.80x80',
persistent: true
}
Office.context.mailbox.item.notificationMessages.replaceAsync('action', message)
setTimeout(() => { event.completed({ allowEvent: true }) }, 10000)
}
})
}
function fetchDataFromOutlookAndSubmitOrUpdateEventToCkt (_callback) {
const callback = (err) => {
if (typeof _callback === 'function') {
_callback(err)
}
}
fetchEventDataFromOutlook((err) => {
if (err) {
console.error('There was some error fetching data from Outlook:', err)
callback(Error('There was some error fetching data from Outlook to CKT Addin'))
} else {
console.success('Data fetched from Outlook assigned to form')
test1 = 20
loadEventMetadata((metadata) => {
console.log('METADATA loded from Outlook: ', metadata)
test1 = JSON.stringify(metadata) + ''
submitUpdateEvent(metadata, (err) => {
if (err) {
console.error('There was an error on submitUpdateEvent', err)
callback(Error('There was some error submitting/updating the event to CKT server'))
} else {
console.success('Data submited/updated to server')
callback()
}
})
})
}
})
}
- Any idea how to console.log in the Edge/webview2 DEV console after we click Send button? I can't simply debug because after I click the Send button, no console.log is displayed. I am consoling for debug on the
Office.MailboxEnums.ItemNotificationMessageType.InformationalMessage
which is quite odd - Any idea why
loadEventMetadata
fetchesmetadata
on normal conditions but fails when itemSend is fired?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看这个文档:
https://learn.microsoft.com/ en-us/office/dev/add-ins/outlook/debug-autolaunch
这实际上不是您的场景,但相同的 regkey 可以工作。 (请确保您的加载项 ID 周围不包含“{}”。因此,请设置以下注册表项:
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\16.0\WEF\Developer\5283AFBB-806E-2D05-BBAF-EF3384D30022
[替换 GUID使用您自己的加载项 ID]
并在该密钥配置单元中设置 UseDirectDebugger = 的 DWORD 1.
当您的加载项启动时(任务窗格、执行函数、项目发送等),您应该会看到一个如下所示的对话框:
从那里您可以将调试器附加到 WebView 并调试您的插件,然后点击确定
Take a look at this documentation:
https://learn.microsoft.com/en-us/office/dev/add-ins/outlook/debug-autolaunch
This isn't actually your scenario, but the same regkey works. (Make sure to not include "{}" around your add-in id. So set the following regkey:
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\16.0\WEF\Developer\5283AFBB-806E-2D05-BBAF-EF3384D30022
[Replace the GUID with your own Add-in ID]
And in that key hive set a DWORD of UseDirectDebugger = 1.
When your add-in launches (taskpane, execute function, itemsend, etc.) you should get a dialog that looks like this:
From there you can attach a debugger to the WebView and debug your add-in, then hit Ok