如何在 Outlook JS 插件中触发 ItemSend 事件后 console.log

How to console.log after ItemSend event is triggered in Outlook JS Addin

我在处理 ItemSend 事件时遇到了真正的问题,因为 MS Outlook 插件提供的生成器使用 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()
          }
        })
      })
    }
  })
}

看看这个文档: https://docs.microsoft.com/en-us/office/dev/add-ins/outlook/debug-autolaunch

这实际上不是您的情况,但可以使用相同的注册码。 (确保不要在您的 add-in id 周围包含“{}”。因此请设置以下注册表项:

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office.0\WEF\Developer83AFBB-806E-2D05-BBAF-EF3384D30022

[用您自己的 Add-in ID 替换 GUID]

然后在该关键配置单元中设置 UseDirectDebugger = 1 的 DWORD。

当您的 add-in 启动时(任务窗格、执行函数、itemsend 等),您应该会看到一个如下所示的对话框:

从那里您可以将调试器附加到 WebView 并调试您的 add-in,然后点击确定