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

如何使用Graph API创建带查阅列的SharePoint列表?

解决Graph API创建SharePoint列表时查阅列关联失效的问题

你遇到的问题核心是查阅列的参数格式不符合Graph API beta版本的要求,同时代码里存在拼写错误,以下是修正方案:

修正后的代码示例

const financeList = {
  displayName: `testlist`,
  columns: [
    { name: "Entity", displayName: "Entity", text: {} },
    { name: "Justification", displayName: "Justification", text: {} },
    { name: "Description", displayName: "Description", text: {} }, // 修正拼写错误
    {
      name: "MacroExpenseItem",
      displayName: "Macro Expense Item",
      lookup: {
        sourceListId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // 替换为目标列表ID
        sourceColumnId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // 替换为目标列表中要引用的列ID
        showField: "Title" // 可选,指定查阅列显示的字段,默认是Title
      },
    },
    { name: "Note", displayName: "Note", text: {} },
  ],
  list: {
    template: "genericList",
  },
};

const newFinanceList = await graph
  .api(newListURL)
  .version("beta")
  .post(financeList);

关键说明

  • 查阅列的lookup属性需使用sourceListId(目标列表ID)和sourceColumnId(目标列表被引用列的ID),而非你之前用的listId和columnId
  • 为每个列添加displayName可保证列表显示的字段名称清晰,避免内部名称与显示名称不一致的问题
  • 确保目标列表已存在于同一站点,且API调用权限足够(如Sites.Manage.All或Sites.FullControl.All)
  • showField参数可选,用于指定查阅列在列表中显示的字段内容,默认值为源列表的Title字段

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 14:10:16