You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Power Automate流因Excel表格空行执行失败,求技术解决方案

问题:Power Automate检测Excel新增行时空行导致流失败

我的Power Automate流用来检测Excel表格是否有新增行,有新增就发送邮件。正常运行无异常,但用户添加未填写ID编号的空行时,流执行失败。尝试用empty和coalesce函数解决但没成功,报错信息如下:

Error:Action 'IF_SP_LP_is_bigger_then_LP_from_excel' failed: Unable to process template language expressions for action 'IF_SP_LP_is_bigger_then_LP_from_excel' at line '0' and column '0': 'The template language function 'int' was invoked with a parameter that is not valid. The value cannot be converted to the target type.'

相关代码:

"type": "If",
  "expression": {
    "or": [
      {
        "greaterOrEquals": [
          "@int(body('Get_item')?['Title'])",
          "@int(coalesce(items('For_each_1')?['LP_x002e_'], '0'))"
        ]
      },
      {
        "equals": [
          "@empty('For_each_1')?['LP_x002e_']",
          "@null"
        ]
      }
    ]
  },

问题原因

  1. coalesce函数未处理空字符串:coalesce仅会替换null值,但空行里的LP_x002e_字段是空字符串'',不属于null,所以coalesce没生效,空字符串传入int()函数就会报错。
  2. 第二个判断条件写法错误:@empty('For_each_1')?['LP_x002e_']是把字符串'For_each_1'传入empty函数,结果永远是false,再取['LP_x002e_']会导致无效引用,根本没起到判断字段是否为空的作用。

修复方案

修改IF条件表达式,先处理空字符串和null的情况,确保传入int()的是有效数字:

方案一:保留原OR逻辑并修正

"type": "If",
  "expression": {
    "or": [
      {
        "greaterOrEquals": [
          "@int(body('Get_item')?['Title'])",
          "@int(coalesce(if(empty(items('For_each_1')?['LP_x002e_']), '0', items('For_each_1')?['LP_x002e_']))"
        ]
      },
      {
        "equals": [
          "@empty(items('For_each_1')?['LP_x002e_'])",
          "@true"
        ]
      }
    ]
  },

方案二:简化逻辑(推荐)

直接把空值(空字符串或null)统一转为0,这样不需要额外的OR条件,空行场景会自动满足greaterOrEquals判断:

"type": "If",
  "expression": {
    "greaterOrEquals": [
      "@int(body('Get_item')?['Title'])",
      "@int(if(empty(items('For_each_1')?['LP_x002e_']), '0', items('For_each_1')?['LP_x002e_']))"
    ]
  },

内容的提问来源于stack exchange,提问作者Sebastian

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 04:47:11