我正在为正在开发的PowerApp创建一个优先级队列系统。优先级队列(RequestPriorityQueue(存储在SharePoint列表中,该列表包含以下列:标题、唯一ID和优先级。Title是表示队列项目的GUID,UniqueID是队列项目的短标识符,Priority是一个数字,其中1是最高优先级。还有一个单独的SharePoint列表(RequestsList(,具有相同的列,以及表示与队列项目关联的数据的其他一些列。
我想做的是用相同的集合修补这两个SharePoint列表,该集合表示由于队列项目的优先级向上或向下移动(将其上方/下方的所有队列项目向下/向上推(而导致的优先级变化。然而,这似乎不起作用——每当我修补优先级列表时,它都会向列表中添加新项目,而不是更新具有相同标题/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");
);
终于想通了。诀窍是使用与SharePoint列表项具有匹配ID的集合进行修补。这对第一个列表来说很容易,但花了一段时间才弄清楚如何更新第二个列表。诀窍是在第一个补丁之后,用第二个列表中的查找(即下面代码中的最后一个UpdateIf(更新集合中的ID。
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");
);