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

如何检查SQL数据库指定行非空/非Null值并取值?Power Automate优化

问题背景

现有Power Automate流程运行正常,流程链路为:

  • 手动触发
  • Get rows(SQL数据库)
  • Apply to Each 容器
  • Get items(SharePoint)
  • 条件判断:length(body('Get_items')?['value']) >= 1
    • 满足条件:无操作
    • 不满足条件:执行Create item(SharePoint)

需求扩展:在执行Create item时,将SQL数据库对应行中非空("")且非Null的会议室列值提取出来,填入SharePoint列表的「会议室」字段。SQL数据库中每个地点对应单独一列存储会议室名称,需遍历该行所有列筛选符合条件的值,要求通过表达式实现。

解决方案

基础版:提取所有非空列值并拼接

如果SharePoint「会议室」是文本字段,使用以下表达式(假设Apply to Each中当前SQL行的引用为items('Apply_to_Each')):

join(
  filter(
    values(items('Apply_to_Each')),
    not(equals(item(), '')) and not(equals(item(), null))
  ),
  ', '
)

表达式说明

  • values(items('Apply_to_Each')):获取当前SQL行的所有列值,返回数组格式
  • filter(...):遍历数组,仅保留非空且非Null的值
  • join(..., ', '):将筛选后的数组拼接为逗号分隔的字符串,适配文本字段格式

进阶版:排除指定非会议室列

如果SQL行包含标题、日期等已单独映射到SP字段的列,需要先排除这些列,再筛选会议室值:

join(
  map(
    filter(
      items('Apply_to_Each'),
      and(
        not(equals(item()?['key'], 'Title')),
        not(equals(item()?['key'], 'EventDate')),
        not(equals(item()?['key'], 'EventTime')),
        not(equals(item()?['value'], '')),
        not(equals(item()?['value'], null))
      )
    ),
    item()?['value']
  ),
  ', '
)

表达式说明

  • items('Apply_to_Each'):以键值对数组形式返回当前SQL行数据
  • filter(...):先排除指定的非会议室列(如Title、EventDate),再过滤掉空值/Null值
  • map(...):提取筛选后键值对中的value部分,得到纯会议室名称数组
  • join(...):拼接为字符串

适配多选字段

如果SharePoint「会议室」是多选选项字段,无需拼接,直接返回筛选后的数组:

filter(
  values(items('Apply_to_Each')),
  not(equals(item(), '')) and not(equals(item(), null))
)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 20:40:58