如何基于单个架构更新两个 SharePoint 列表? (PowerApps)
How can I update two SharePoint lists based on a single schema? (PowerApps)
我正在尝试为我正在开发的 PowerApp 创建一个优先级队列系统。优先级队列 (RequestPriorityQueue) 存储在包含以下列的 SharePoint 列表中:Title、UniqueID 和 Priority。 Title 是表示队列项的 GUID,UniqueID 是队列项的短标识符,Priority 是一个数字,1 为最高优先级。还有一个单独的 SharePoint 列表 (RequestsList),其中包含相同的列,以及表示与队列项目关联的数据的许多其他列。
我想做的是用同一个集合修补这两个 SharePoint 列表,该集合表示优先级因队列项目的优先级上升或下降而发生变化(这会将所有队列项目推入 above/below down/up队列)。但是,这似乎不起作用 - 每当我修补优先级列表时,它都会将新项目添加到列表中,而不是使用相同的 Title/UniqueID 更新列表项目 - 我做错了什么?
If(!(ThisItem.Priority = PriorityDropdown.Selected.Value),
ClearCollect(PrioritiesToChange, {Title: "init", UniqueID0: Blank(), Priority: -1});
ForAll(ShowColumns(RequestPriorityQueue, "Title", "UniqueID0", "Priority"), Collect(PrioritiesToChange, {Title: Title, UniqueID0: UniqueID0, Priority: Priority}));
If(ThisItem.Priority > PriorityDropdown.Selected.Value,
ClearCollect(PrioritiesToChange, Filter(PrioritiesToChange, Priority >= PriorityDropdown.Selected.Value && Priority < ThisItem.Priority));
UpdateIf(PrioritiesToChange, true, {Priority: Priority + 1});
UpdateIf(PrioritiesToChange, Title = ThisItem.Title, {Priority: PriorityDropdown.Selected.Value});,
ClearCollect(PrioritiesToChange, Filter(RequestPriorityQueue, Priority <= PriorityDropdown.Selected.Value && Priority > ThisItem.Priority));
UpdateIf(PrioritiesToChange, true, {Priority: Priority - 1});
UpdateIf(PrioritiesToChange, Title = ThisItem.Title, {Priority: PriorityDropdown.Selected.Value});
);
RemoveIf(PrioritiesToChange, Title = "init");
Patch(RequestPriorityQueue, PrioritiesToChange);
Patch(RequestsList, PrioritiesToChange);
Refresh(RequestsList);
Notify("Priority changed");
);
终于想通了。诀窍是使用具有匹配 ID 的集合来修补 SharePoint 列表项。这对于第一个列表来说很容易,但花了一段时间才弄清楚如何更新第二个列表。诀窍是在第一个补丁之后使用第二个列表中的查找更新集合中的 ID(即下面代码中的最后一个 UpdateIf)。
If(!(ThisItem.Priority = PriorityDropdown.Selected.Value),
ClearCollect(PrioritiesToChange, ShowColumns(RequestPriorityQueue, "ID", "Priority", "Title"));
If(ThisItem.Priority > PriorityDropdown.Selected.Value,
ClearCollect(PrioritiesToChange, Filter(PrioritiesToChange, Priority >= PriorityDropdown.Selected.Value && Priority <= ThisItem.Priority));
UpdateIf(PrioritiesToChange, true, {Priority: Priority + 1});
UpdateIf(PrioritiesToChange, Title = ThisItem.Title, {Priority: PriorityDropdown.Selected.Value});,
ClearCollect(PrioritiesToChange, Filter(RequestPriorityQueue, Priority <= PriorityDropdown.Selected.Value && Priority >= ThisItem.Priority));
UpdateIf(PrioritiesToChange, true, {Priority: Priority - 1});
UpdateIf(PrioritiesToChange, Title = ThisItem.Title, {Priority: PriorityDropdown.Selected.Value});
);
Patch(RequestPriorityQueue, ShowColumns(PrioritiesToChange, "ID", "Priority", "Title"));
UpdateIf(PrioritiesToChange, true, {ID: LookUp(RequestsList, RequestsList[@Title] = PrioritiesToChange[@Title]).ID});
Patch(RequestsList, ShowColumns(PrioritiesToChange, "ID", "Priority", "Title"));
Refresh(RequestsList);
Notify("Priority changed");
);
我正在尝试为我正在开发的 PowerApp 创建一个优先级队列系统。优先级队列 (RequestPriorityQueue) 存储在包含以下列的 SharePoint 列表中:Title、UniqueID 和 Priority。 Title 是表示队列项的 GUID,UniqueID 是队列项的短标识符,Priority 是一个数字,1 为最高优先级。还有一个单独的 SharePoint 列表 (RequestsList),其中包含相同的列,以及表示与队列项目关联的数据的许多其他列。
我想做的是用同一个集合修补这两个 SharePoint 列表,该集合表示优先级因队列项目的优先级上升或下降而发生变化(这会将所有队列项目推入 above/below down/up队列)。但是,这似乎不起作用 - 每当我修补优先级列表时,它都会将新项目添加到列表中,而不是使用相同的 Title/UniqueID 更新列表项目 - 我做错了什么?
If(!(ThisItem.Priority = PriorityDropdown.Selected.Value),
ClearCollect(PrioritiesToChange, {Title: "init", UniqueID0: Blank(), Priority: -1});
ForAll(ShowColumns(RequestPriorityQueue, "Title", "UniqueID0", "Priority"), Collect(PrioritiesToChange, {Title: Title, UniqueID0: UniqueID0, Priority: Priority}));
If(ThisItem.Priority > PriorityDropdown.Selected.Value,
ClearCollect(PrioritiesToChange, Filter(PrioritiesToChange, Priority >= PriorityDropdown.Selected.Value && Priority < ThisItem.Priority));
UpdateIf(PrioritiesToChange, true, {Priority: Priority + 1});
UpdateIf(PrioritiesToChange, Title = ThisItem.Title, {Priority: PriorityDropdown.Selected.Value});,
ClearCollect(PrioritiesToChange, Filter(RequestPriorityQueue, Priority <= PriorityDropdown.Selected.Value && Priority > ThisItem.Priority));
UpdateIf(PrioritiesToChange, true, {Priority: Priority - 1});
UpdateIf(PrioritiesToChange, Title = ThisItem.Title, {Priority: PriorityDropdown.Selected.Value});
);
RemoveIf(PrioritiesToChange, Title = "init");
Patch(RequestPriorityQueue, PrioritiesToChange);
Patch(RequestsList, PrioritiesToChange);
Refresh(RequestsList);
Notify("Priority changed");
);
终于想通了。诀窍是使用具有匹配 ID 的集合来修补 SharePoint 列表项。这对于第一个列表来说很容易,但花了一段时间才弄清楚如何更新第二个列表。诀窍是在第一个补丁之后使用第二个列表中的查找更新集合中的 ID(即下面代码中的最后一个 UpdateIf)。
If(!(ThisItem.Priority = PriorityDropdown.Selected.Value),
ClearCollect(PrioritiesToChange, ShowColumns(RequestPriorityQueue, "ID", "Priority", "Title"));
If(ThisItem.Priority > PriorityDropdown.Selected.Value,
ClearCollect(PrioritiesToChange, Filter(PrioritiesToChange, Priority >= PriorityDropdown.Selected.Value && Priority <= ThisItem.Priority));
UpdateIf(PrioritiesToChange, true, {Priority: Priority + 1});
UpdateIf(PrioritiesToChange, Title = ThisItem.Title, {Priority: PriorityDropdown.Selected.Value});,
ClearCollect(PrioritiesToChange, Filter(RequestPriorityQueue, Priority <= PriorityDropdown.Selected.Value && Priority >= ThisItem.Priority));
UpdateIf(PrioritiesToChange, true, {Priority: Priority - 1});
UpdateIf(PrioritiesToChange, Title = ThisItem.Title, {Priority: PriorityDropdown.Selected.Value});
);
Patch(RequestPriorityQueue, ShowColumns(PrioritiesToChange, "ID", "Priority", "Title"));
UpdateIf(PrioritiesToChange, true, {ID: LookUp(RequestsList, RequestsList[@Title] = PrioritiesToChange[@Title]).ID});
Patch(RequestsList, ShowColumns(PrioritiesToChange, "ID", "Priority", "Title"));
Refresh(RequestsList);
Notify("Priority changed");
);