如何使用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
相关产品推荐
相关产品推荐

