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

Power App中用Power Automate从Google Sheet取数无法显示在TextInput的问题

Power Apps中无法将Power Automate获取的Google Sheet数据显示到TextInput字段

问题说明

我在Power App中搭建了Power Automate流DM_Sheet_Search,用于根据输入的主键从Google Sheet查询特定行数据。点击搜索按钮后,数据已成功获取,但无法显示到对应的TextInput字段中,需要解决该问题以实现数据的更新/删除操作。

搜索按钮现有代码

// Trigger the flow and store the response
Set(
    response,
    DM_Sheet_Search.Run(TextInput1.Text) //DM_Sheet_Search是流名称
);

// Debugging: Display the entire response using JSON
Notify("Response received: " & JSON(response, JSONFormat.Compact), NotificationType.Information);

// Check if response contains expected fields and update text input fields
If(
    !IsError(response),
    // 假设响应是包含字段的对象
    If(
        !IsBlank(response.review),
        UpdateContext({ textInput1_1Value: response.review })
    );
    If(
        !IsBlank(response.msshrutireview),
        UpdateContext({ textInput1_2Value: response.msshrutireview})
    );
    If(
        !IsBlank(response.mrgirishreview),
        UpdateContext({ textInput1_3Value: response.mrgirishreview})  //a,b,c是Google Sheet的列名
    )
);

// Ensure text input fields are updated with variable values
TextInput1_1.Text = textInput1_1Value;
TextInput1_2.Text = textInput1_2Value;
TextInput1_3.Text = textInput1_3Value;

Power Automate流输出信息

Get Rows操作输出Body

{
  "@odata.context": "https://googledrive-ci.azconn-ci-001.p.azurewebsites.net/$metadata#datasets('1nySnd4-PKJfSIoOnXe31D_M-wiZeIlKWPVOTW8NUxmg')/tables('495289366')/items",
  "value": [
 {
  "@odata.etag": "",
  "ItemInternalId": "61a29650d840475b877250f1dbc0c561",
  "SR_No": "1",
  "Sheet_Name": "PROVIDED SERVICES TO INDUSTRY",
  "Review": "Similar Webite To Beneficiation",
  "Ms_Shruti_Review": "In Progress",
  "Mr_Girish_Review": "In Progress",
  "__PowerAppsId__": "61a29650d840475b877250f1dbc0c561,2"
  },
  // 其余行省略
  ],
  "@odata.nextLink": "https://india-001.azure-apim.net/apim/googlesheet/0f06f26272de40baa02f8945bc5625f5/datasets/1nySnd4-PKJfSIoOnXe31D_M-wiZeIlKWPVOTW8NUxmg/tables/495289366/items?%24skip=256"
}

Filter操作输出

[
 {
 "@odata.etag": "",
 "ItemInternalId": "61a29650d840475b877250f1dbc0c561",
 "SR_No": "1",
 "Sheet_Name": "PROVIDED SERVICES TO INDUSTRY",
 "Review": "Similar Webite To Beneficiation",
 "Ms_Shruti_Review": "In Progress",
 "Mr_Girish_Review": "In Progress",
 "__PowerAppsId__": "61a29650d840475b877250f1dbc0c561,2"
 }
]

问题分析与修复方案

核心问题

  1. 响应结构错误:Filter操作输出是数组,但代码中直接将response当作对象处理,未提取数组中的第一个元素。
  2. 字段名不匹配:流返回的字段名是Review、Ms_Shruti_Review、Mr_Girish_Review,但代码中使用的是小写无下划线的review、msshrutireview、mrgirishreview,字段名大小写和格式不匹配导致无法取值。
  3. TextInput赋值方式错误:Power Apps中不能直接用=给控件的Text属性赋值,需要通过变量绑定或直接设置上下文变量后让控件绑定变量。

修复后的代码

// 触发流并存储响应
Set(
    response,
    DM_Sheet_Search.Run(TextInput1.Text)
);

// 调试:显示完整响应
Notify("Response received: " & JSON(response, JSONFormat.Compact), NotificationType.Information);

// 处理响应数据
If(
    !IsError(response) && !IsBlank(response.value) && CountRows(response.value) > 0,
    // 提取数组中的第一个匹配行
    Set(selectedRow, First(response.value));
    // 更新上下文变量,注意字段名与流输出一致
    UpdateContext({
        textInput1_1Value: selectedRow.Review,
        textInput1_2Value: selectedRow.Ms_Shruti_Review,
        textInput1_3Value: selectedRow.Mr_Girish_Review
    })
);

控件绑定设置

将三个TextInput控件的Text属性分别绑定到对应的上下文变量:

  • TextInput1_1.Text = textInput1_1Value
  • TextInput1_2.Text = textInput1_2Value
  • TextInput1_3.Text = textInput1_3Value

(注:控件属性绑定需在Power Apps编辑器的属性面板中设置,而非在按钮代码里直接赋值)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 08:51:07