1. Students Counter
Prior to sharing the Batching saving coding, I wish to include the Counter for Students (as part of showing total of students of the class, No of present and absent student).
Formula
Counter for Students, Present and Absent
TextBox1.Text = CountRows(StudentList)
TextBox.1_1Text = CountRows(Filter(TableAttendance, Date = 'Today-Date'.Text && Grade = DropdownGrade.Selected.Result && Attendance = "True"))
TextBox1_2.Text = TextBox3_5.Text - TextBox3_6.Text
2. Grade & Teach Dropdown
These two dropdowns are used for different purposes:
Formula
DropdownGrade.OnChange or OnSelect = ClearCollect(StudentList, Filter(TableStudentList, Grade = DropdownGrade.Selected.Result))
DropdownTeacher.Default = LookUp(TableAttendance, Date = 'Today-Date'.Text && Grade = DropdownGrade.Selected.Result && StudentName = 'Student-Name'.Text).Teacher
Rational Reason
What happens on selection of Dropdown:
Grade:
Teacher:
Date:
3. Saving
As mentioned earlier (Part 1), Batch saving is important and with the introduction of ForAll, life has become easier.
Formula
Saving (Check) Icon.OnSelect =
UpdateContext({attendancetoggle: true, reasonselect: true, LoadingIcon: true});
If(CountRows(Filter(TableAttendance, Date = 'Today-Date'.Text && Grade = DropdownGrade.Selected.Result)) = 0,
Patch(TableAttendance, ForAll(Gallery1.AllItems,
{StudentName: 'Student-Name'.Text, Grade: DropdownGrade.Selected.Result, Attendance: Toggle1.Value, Date: 'Today-Date'.Text, Reason: DropdownReason.Selected.Value, Teacher: DropdownTeacher.Selected.Result})));
UpdateContext({LoadingIcon: false, attendancetoggle: false, reasonselect: false})
Sequential action:
UpdateContext({attendancetoggle: true, reasonselect: true, LoadingIcon: true})
Attendancetoggle, reasonselect LoadingIcon:
These are defined variable for Toggle and Dropdown so that they become DISABLE during saving and Enabled after saving to avoid unnecessary change of value during saving period.
Meantime, the LoadingIcon (Animated GIF) will start to show saving process (it can also see the …. Moving from left to right but not obvious to user).
This a Media, with GIF file (it is added into Media*, named as “LoadingIcon”) added to show the effect / alert user when the data is being save!
- UpdateContext({LoadingIcon: true,…});…..Saving in progress….; UpdateContext({LoadingIcon: false, …})
If(CountRows(Filter(TableAttendance, Date = 'Today-Date'.Text && Grade = DropdownGrade.Selected.Result)) = 0,
Patch(TableAttendance, ForAll(Gallery1.AllItems,
{StudentName: 'Student-Name'.Text, Grade: DropdownGrade.Selected.Result, Attendance: Toggle1.Value, Date: 'Today-Date'.Text, Reason: DropdownReason.Selected.Value, Teacher: DropdownTeacher.Selected.Result})));
The first CountRows serve to counter-check that no data available for that particular DATE & GRADE (it means, a new record).
Then, start the Patching (Saving) Process, by using ForAll of the Gallery1.AllItems, and save all the related fields within { …. }.
UpdateContext({LoadingIcon: false, attendancetoggle: false, reasonselect: false})
Once Saving process is completed, UpdateContext will force to false the initial context variable.
Note:
Saving (Check) Icon.OnVisible = If(CountRows(Filter(TableAttendance, Date = 'Today-Date'.Text && Grade = DropdownGrade.Selected.Result)) <> 0, false, true)
Rational Reason
Saving (Check) will appear when:
ICON will disappear, leaving the teacher to depend on Toggle to UPDATE attendance status.
Final Part
I will touch on how to use UpdateIf to update selected record / field only.
For me, this is very interesting as it took much of my time to ensure change(s) is(are) updated instantly and user-friendly.
See you next time…