Hello all,
I have a gallery set up with checkboxes to select and patch one or more records into a collection called "colCheckedRecords". I then use a ForAll loop to do an updating or patching function on all the records found in my collection. This largely works very well, but I am seeing an issue where the very last record I "Check" will indicate the record has been added to the collection but the patch does not occur.
A little bit more info: I'm using this to update a "status" column for each of the "Checked" records. I'm usually selecting between 3 and 7 records in the gallery. Only the last one does not patch my updated status to my SQL list.
Any thoughts or ideas on this?
Thanks!
Solved! Go to Solution.
I would perhaps take a slightly different approach to this. Since you are most likely using this in a Gallery (your CheckBox) instead use that as your collection (because it already is).
Your button OnSelect action formula would become this:
ForAll(
Filter(yourGallery.AllItems, yourCheckbox.Value) as galItem,
UpdateIf('[dbo].[ActiveList]', Id = galItem.Id,
{statusNumber:
Switch(CurrentUserDept,
"Department1", 2,
"Department2", 4,
"Department3", 5
),
UserModified: User().FullName,
TimeModified: Now()
}
)
);
@MaxEgn
Can you provide some of the formulas you are using that are causing the issue?
This is the only code associated with "On Check" of the checkbox.
Collect(colCheckedItems, ThisItem);
UpdateContext({Checkbox: true})
The Button that patches the collection code:
ForAll(
ShowColumns(colCheckedItems, "Id", "statusNumber"),
Patch('[dbo].[ActiveList]', ThisRecord,
Switch(CurrentUserDept,
"Department1", {statusNumber: 2},
"Department2", {statusNumber: 4},
"Department3", {statusNumber: 5},
{UserModified: User().FullName},
{TimeModified: Now()}
));
Clear(colCheckedItems);
UpdateContext({Checkbox: false});
It seems pretty straightforward so I'm not sure why there is this intermittent issue. It seems to happen more when the clicks are faster, but it still only occurs every few times with 3 or more records.
I would perhaps take a slightly different approach to this. Since you are most likely using this in a Gallery (your CheckBox) instead use that as your collection (because it already is).
Your button OnSelect action formula would become this:
ForAll(
Filter(yourGallery.AllItems, yourCheckbox.Value) as galItem,
UpdateIf('[dbo].[ActiveList]', Id = galItem.Id,
{statusNumber:
Switch(CurrentUserDept,
"Department1", 2,
"Department2", 4,
"Department3", 5
),
UserModified: User().FullName,
TimeModified: Now()
}
)
);
This solution does work for the first half of my function! Thank you!
However I do still have a need of doing the same functionality but patching the selected records from the gallery as a new record to a different database in addition to updating a column in my existing record.
Is there a way to switch out "Update if" with an actual Patch function? I've been struggling with "incompatible type" errors for a while now.
Good to hear things are progressing.
So, if it is that you need to instead put this into another datasource, then consider the following formula:
Collect(yourOtherSource,
ForAll(
Filter(yourGallery.AllItems, yourCheckbox.Value) as galItem,
Patch(Defaults(yourOtherSource),
{statusNumber:
Switch(CurrentUserDept,
"Department1", 2,
"Department2", 4,
"Department3", 5
),
UserModified: User().FullName,
TimeModified: Now()
}
)
)
);
I kept the original column names you had for the other list, but please adjust as needed.
This formula will create a table of all the new records you want, and then submit them to the other datasource in one function (collect).
User | Count |
---|---|
229 | |
106 | |
93 | |
57 | |
30 |
User | Count |
---|---|
291 | |
119 | |
106 | |
62 | |
57 |