首页 > 解决方案 > ADF v2 - 如何向 Teams 发送错误消息?

问题描述

我使用此模板向 Teams 频道发送通知。

在此处输入图像描述

但我发现,它不能发送错误信息。因为它无法将字符串解析为 json。

Operation on target Call Teams Webhook failed: The function 'json' parameter is not valid. The provided value '{ "@type": "MessageCard", "@context": "http://schema.org/extensions", "themeColor": "0076D7", "summary": "Pipeline status alert message​​​​", "sections": [ { "activityTitle": "Pipeline alert​​​​", "facts": [ { "name": "Pipeline RunId:", "value": "8b5b8400-346f-425a-8a64-f63bcf993370" }, { "name": "Activity name:", "value": "[CosmosDB Backup] Backup Data Error" }, { "name": "Activity status:", "value": "Failed" }, { "name": "Execution duration (s):", "value": "1" }, { "name": "Message", "value": "{ "message": "Different
...
annot be parsed: 'After parsing a value an unexpected character was encountered: m. Path 'sections[0].facts[4].value', line 29, position 3

在此处输入图像描述

想到的唯一方法是“通过{}剪切字符串”

标签: azure-data-factory-2

解决方案


  1. 将字符串剪断{}
@substring(
  activity('xxx').error.message,
  indexof(activity('xxx').error.message,'{'),
  add(
      sub(lastindexof(activity('xxx').error.message,'}'),indexof(activity('xxx').error.message,'{'))
  ,1)
)
  1. @json()上面的结果
  2. 得到你想要的价值

完整代码:

@json(substring(
activity('xxx').error.message,
indexof(activity('xxx').error.message,'{'),
add(sub(lastindexof(activity('xxx').error.message,'}'),indexof(activity('xxx').error.message,'{')),1)
)).message

我想要 JSON 对象的消息。


推荐阅读