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

如何提交SharePoint表单时同步更新Power Apps中超链接列的描述

如何在提交Power Apps表单时更新SharePoint超链接列的描述

本问题是《如何在Power Apps中获取来自SharePoint的超链接显示名称》的后续问题

以下是我在应用的On Start事件中使用的代码:

Set(AllFavorites; GruposdoOffice365.HttpRequest("https://graph.microsoft.com/v1.0/sites/X/Lists/Y/items?expand=fields"; "GET"; ""));;

ClearCollect(
    colAllFavorites;
    ForAll(
        Table(AllFavorites.value);
        {
            Title: Text(Value.fields.Title);
            Url1: Text(Value.fields.Legisla_x00e7__x00e3_o_x0020_Ref.Url);
            Description1: Text(Value.fields.Legisla_x00e7__x00e3_o_x0020_Ref.Description);
            Url2: Text(Value.fields.Legisla_x00e7__x00e3_o_x0020_Ref0.Url);
            Description2: Text(Value.fields.Legisla_x00e7__x00e3_o_x0020_Ref0.Description);
            Url3: Text(Value.fields.Legisla_x00e7__x00e3_o_x0020_Ref1.Url);
            Description3: Text(Value.fields.Legisla_x00e7__x00e3_o_x0020_Ref1.Description);
            Url4: Text(Value.fields.Legisla_x00e7__x00e3_o_x0020_Ref2.Url);
            Description4: Text(Value.fields.Legisla_x00e7__x00e3_o_x0020_Ref2.Description);
            Url5: Text(Value.fields.Legisla_x00e7__x00e3_o_x0020_Ref3.Url);
            Description5: Text(Value.fields.Legisla_x00e7__x00e3_o_x0020_Ref3.Description)
        }
    )
);;

我已经通过应用启动时的HTTP请求获取到超链接列的描述并显示在文本框中,现在需要在提交SharePoint表单的同时,保存文本框中对该描述的修改,请问如何实现提交表单时对SharePoint超链接列描述执行Upsert操作?

我已将URL与对应的链接进行颜色编码,高亮按钮为数据提交按钮:
界面截图


实现步骤

1. 保留原始项的ID(关键)

先修改OnStart中的集合创建逻辑,把SharePoint项的ID存入集合,后续更新需要用ID定位目标项:

Set(AllFavorites; GruposdoOffice365.HttpRequest("https://graph.microsoft.com/v1.0/sites/X/Lists/Y/items?expand=fields"; "GET"; ""));;

ClearCollect(
    colAllFavorites;
    ForAll(
        Table(AllFavorites.value);
        {
            ID: Value.id; // 新增:保存项的唯一ID
            Title: Text(Value.fields.Title);
            Url1: Text(Value.fields.Legisla_x00e7__x00e3_o_x0020_Ref.Url);
            Description1: Text(Value.fields.Legisla_x00e7__x00e3_o_x0020_Ref.Description);
            Url2: Text(Value.fields.Legisla_x00e7__x00e3_o_x0020_Ref0.Url);
            Description2: Text(Value.fields.Legisla_x00e7__x00e3_o_x0020_Ref0.Description);
            Url3: Text(Value.fields.Legisla_x00e7__x00e3_o_x0020_Ref1.Url);
            Description3: Text(Value.fields.Legisla_x00e7__x00e3_o_x0020_Ref1.Description);
            Url4: Text(Value.fields.Legisla_x00e7__x00e3_o_x0020_Ref2.Url);
            Description4: Text(Value.fields.Legisla_x00e7__x00e3_o_x0020_Ref2.Description);
            Url5: Text(Value.fields.Legisla_x00e7__x00e3_o_x0020_Ref3.Url);
            Description5: Text(Value.fields.Legisla_x00e7__x00e3_o_x0020_Ref3.Description)
        }
    )
);;

2. 绑定文本框到集合字段

确保每个描述文本框的Default属性绑定到集合对应的DescriptionX字段,比如第一个描述框的Default设为:ThisItem.Description1,修改后的值会自动同步到集合中。

3. 在提交按钮的OnSelect中执行更新

点击提交按钮时,先提交表单(如果有其他字段用Form控件),再调用Graph API更新超链接列的描述:

// 先提交表单(如果使用Form控件管理其他字段)
SubmitForm(你的表单控件名);;

// 获取当前要更新的项(假设用Gallery展示,取选中项)
Set(currentItem; Gallery1.Selected);;

// 构造超链接列的更新数据
Set(updateData; 
    {
        fields: {
            Legisla_x00e7__x00e3_o_x0020_Ref: {
                Url: currentItem.Url1;
                Description: TextInput1.Text // 第一个描述文本框的修改后值
            };
            Legisla_x00e7__x00e3_o_x0020_Ref0: {
                Url: currentItem.Url2;
                Description: TextInput2.Text // 第二个描述文本框的修改后值
            };
            Legisla_x00e7__x00e3_o_x0020_Ref1: {
                Url: currentItem.Url3;
                Description: TextInput3.Text
            };
            Legisla_x00e7__x00e3_o_x0020_Ref2: {
                Url: currentItem.Url4;
                Description: TextInput4.Text
            };
            Legisla_x00e7__x00e3_o_x0020_Ref3: {
                Url: currentItem.Url5;
                Description: TextInput5.Text
            }
        }
    }
);;

// 调用Graph API执行更新(PATCH方法用于修改已有项)
GruposdoOffice365.HttpRequest(
    $"https://graph.microsoft.com/v1.0/sites/X/Lists/Y/items/{currentItem.ID}/fields";
    "PATCH";
    JSON(updateData)
);;

// 刷新集合,同步本地数据
Refresh(colAllFavorites);;

关键说明

  • 使用PATCH方法更新指定项的字段,Graph API中修改列表项字段需请求对应项的fields端点。
  • 超链接列必须传入包含Url和Description的完整对象,即使Url未修改也要保留,避免被覆盖为空。
  • 确保GruposdoOffice365连接拥有Sites.ReadWrite.All权限,以允许修改SharePoint列表项。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 11:04:59