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

Flow模板语言报错求助:split函数遇Null值致流程偶发失败

问题描述

流程偶发无规律失败,手动重新运行可恢复,需彻底解决该问题。

报错信息

Unable to process template language expressions in action 'Periodo' inputs at line '0' and column '0': 'The template language function 'split' expects its first parameter to be of type string. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#split for usage details.'

错误仅出现在Client和Periodo两个变量上,所有4个变量均为字符串类型(数字形式)。

变量配置

Client变量公式

trim(first(split(first(skip(split(outputs('Compos'),'client = '),1)),'indicator')))

Periodo变量公式

trim(first(split(first(skip(split(outputs('Compos'),'period = '),1)),'DATA_REPORT_DELIVERY')))

数据源示例(提取信息的邮件内容)

CO NIV ICE REFRESCOS DE SOYA has finished successfully.CO NIV ICE REFRESCOS DE SOYA

User
    binary.struggle@mail.com

Parameters
    output = 7
    country = 170
    period = 202204012
    DATA_REPORT_DELIVERY = NO
    read_persistance = YES
    write_persistance = YES
    client = 18277
    indicator_group = SALES

解决方案

问题根源是偶发情况下,outputs('Compos')中找不到client = 或period = 目标字符串,导致split返回的数组长度不足2,skip(...,1)后取first()得到Null,传入内层split时触发报错。

基础修复:添加空值兜底

修改公式,用coalesce给可能为空的结果设置默认空字符串,避免Null传入split:

修改后的Client变量公式

trim(
    first(
        split(
            coalesce(
                first(skip(split(outputs('Compos'),'client = '),1)),
                ''
            ),
            'indicator'
        )
    )
)

修改后的Periodo变量公式

trim(
    first(
        split(
            coalesce(
                first(skip(split(outputs('Compos'),'period = '),1)),
                ''
            ),
            'DATA_REPORT_DELIVERY'
        )
    )
)

进阶优化:先判断字符串存在性

如果需要更严谨的逻辑,可提前判断目标字符串是否存在,再执行提取:

带存在性判断的Client公式

if(
    contains(outputs('Compos'),'client = '),
    trim(first(split(first(skip(split(outputs('Compos'),'client = '),1)),'indicator'))),
    ''
)

带存在性判断的Periodo公式

if(
    contains(outputs('Compos'),'period = '),
    trim(first(split(first(skip(split(outputs('Compos'),'period = '),1)),'DATA_REPORT_DELIVERY'))),
    ''
)

修改后,即使偶发找不到目标字符串,流程也会返回空字符串而非触发报错,后续可根据空值添加告警或补充处理逻辑。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.07 04:02:57