Hello everyone,
I'm trying to patch multiple rows to a collection and then to a sharepoint list. However, I'm experiencing difficulties with one of the columns that is a LookUp column. I'm not sure what I have is correct and in addition to that, I get the squiggly lines for the part that is supposed to load new entries to the collection.
This is the collection I'm trying to patch:
ClearCollect(
colUpdates,
{
ID: 1,
Title: "A",
Department1: {Id: 1, Value: drd_NewBudget_Department.Selected.Value},
Unit1: {Id: 1, Value: drd_NewBudget_Unit_1.Selected.Value},
Year: {Value: "A"},
StartingBudget: 1,
CurrentBalance: 1,
LineItem: "A"
}
);
Clear(colUpdates);
These are the records I'm trying to patch...
// Go through each record and filter those items that have been changed or updated. Update corresponding records in the Budget sharepoint list, then set the varGalleryMode to blank so it can go back to View only mode.
//The save icon has a different behaviour when the gallery is in new mode vs edit mode.
// Create a collection to store updated values
If(
// Do this when new entries are being created
varGalleryMode="New",
// Load all new entries into the collection colUpdates
ForAll(
gal_NewBudget_2.AllItems As NewRows,
Patch(colUpdates,
LookUp(colUpdates, ID=NewRows.ID), {
Department1: {Id: NewRows.ID, Value: NewRows.drd_NewBudget_Department.Selected.Value},
Title: NewRows.txt_NewBudget_Code_1.Text,
Unit1: {Value: NewRows.drd_NewBudget_Unit.Selected.Value},
Year: {Value: NewRows.drd_NewBudget_Year.Selected.Value},
StartingBudget: Value(NewRows.txt_NewBudget_StartingBudget.Text),
//Make the current balance the same value as the starting budget.
CurrentBalance: Value(NewRows.txt_NewBudget_StartingBudget.Text),
LineItem: NewRows.txt_NewBudget_LineItem.Text
});
);
// Clear any ID numbers from colUpdates and delete the last row which holds no info
UpdateIf(colUpdates, true, {ID: Blank()});
Remove(colUpdates, Last(colUpdates)),
// Do this when entries are being edited
varGalleryMode="Edit",
//hold the old starting budget in a collection here. also hold the old current balance.
// Load changed entries into the collection colUpdates
ForAll(
Filter(
gal_NewBudget_2.AllItems,
tog_NewBudget_isChanged_1.Value
) As ChangedRows,
Patch(colUpdates,
Defaults(colUpdates), {
ID: ChangedRows.ID,
Department1: {Id: ChangedRows.ID, Value: ChangedRows.drd_NewBudget_Department.Selected.Value},
Title: ChangedRows.txt_NewBudget_Code_1.Text,
Unit1: {Id: ChangedRows.ID, Value: ChangedRows.drd_NewBudget_Unit.Selected.Value},
Year: {Value: ChangedRows.drd_NewBudget_Year.Selected.Value},
StartingBudget: Value(ChangedRows.txt_NewBudget_StartingBudget.Text),
//remove this current balance from here and patch it separately?
CurrentBalance: Value(ChangedRows.txt_NewBudget_CurrentBalance.Text),
LineItem: ChangedRows.txt_NewBudget_LineItem.Text
})
)
);
// Update SharePoint with new values or changed values for existing rows
Patch(Budgets, colUpdates);
//collect the new starting budget in another collection here
//create a context variable that is the difference between the new starting budget and the old starting budget.
//add the variable to the old current balance to get the new current balance.
//then patch the new current balance by doing the whole ForAll thing again?
Clear(colUpdates);
//Collect the collection again to get the new sum after new item has been added.
ClearCollect(colBudgetFilter, If(User().Email = lbl_UnitControls_DeptHead.Text, Filter(Budgets, Department1.Value = lbl_UnitControls_Dept.Text), Filter(Budgets, Unit1.Value = lbl_UnitControls_Unit.Text)));
// check for errors
If(
IsEmpty(Errors(Budgets)),
// on success
Notify(
"Success: Changes Have Been Updated",
NotificationType.Success
),
// on failure
Notify(
"Errors: Changes Have Not Been Updated",
NotificationType.Error
)
);
// Return gallery to view mode
Set(varGalleryMode, Blank());
This is the part that gives me the squiggly lines. Any help will be appreciated. Thanks.
