Outllook插件函数getRegExMatches()始终返回null

问题描述 投票:0回答:1

我正在尝试开发一个Outlook加载项,该加载项在邮件正文中使用regex查找表达式,但是getRegExMatches()始终为我提供null。

我不知道该怎么做,所以我尝试了https://docs.microsoft.com/en-us/office/dev/add-ins/reference/objectmodel/requirement-set-1.5/office.context.mailbox.item?product=outlook&version=v1.5#getregexmatches--object中的示例

示例规则的代码是

<Rule xsi:type="RuleCollection" Mode="And">
  <Rule xsi:type="ItemIs" FormType="Read" ItemType="Message" />
  <Rule xsi:type="RuleCollection" Mode="Or">
    <Rule xsi:type="ItemHasRegularExpressionMatch" RegExName="fruits" RegExValue="apple|banana|coconut" PropertyName="BodyAsPlaintext" IgnoreCase="true" />
    <Rule xsi:type="ItemHasRegularExpressionMatch" RegExName="veggies" RegExValue="tomato|onion|spinach|broccoli" PropertyName="BodyAsPlaintext" IgnoreCase="true" />
  </Rule>
</Rule>

并且在javascript中,我可以这样称呼此规则

var allMatches = Office.context.mailbox.item.getRegExMatches();
var fruits = allMatches.fruits;
var veggies = allMatches.veggies;

var allMatches是给我一个空值的变量,因为其他2个变量给出了错误。本来应该提供一个带有字符串的数组,该字符串必须等于规则中的字符串(例如苹果,香蕉等)。

outlook outlook-addin outlook-web-addins
1个回答
0
投票

正则表达式规则应仅在检测到的实体的上下文中起作用。您可以在此处了解更多信息:https://docs.microsoft.com/en-us/outlook/add-ins/contextual-outlook-add-ins。您是从检测到的实体中将外接程序作为上下文外接程序运行吗?如果不是,请使用Body.getAsync获取正文,然后尝试使用正则表达式在正文中进行搜索。

© www.soinside.com 2019 - 2024. All rights reserved.