web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :

Apps with Batch Saving & Single Record Updating [Part 2]

hpkeong Profile Picture hpkeong 2,944

 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

  • - Total No of Student:

           TextBox1.Text = CountRows(StudentList)

  • - Present:

TextBox.1_1Text = CountRows(Filter(TableAttendance, Date = 'Today-Date'.Text && Grade = DropdownGrade.Selected.Result && Attendance = "True"))

  • - Absent:

           TextBox1_2.Text = TextBox3_5.Text - TextBox3_6.Text

 

Student CounterStudent Counter

 2. Grade & Teach Dropdown

These two dropdowns are used for different purposes:

  1. Grade: to filter and display in the gallery all the students from the selected grade
  2. Teacher: to select the teacher (will be saved together with the selected grade) who marks the attendance

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:

  • - This will utilize temporary table “StudentList” (this is ONE of the MAIN REASON it is ClearCollect first because it will be used for all kind of filtering, selection, etc.) as a COMMON datasource NAME!

Teacher:

  • - This is just to SHOW (by default after saving) or SELECT which teacher is doing the attendance check

Date:

  • - This is a BUTTON (I am not using TextBox because Button can be easily clicked or touched as explained in Part I!)
  • - Button.OnSelect = UpdateContext({X:0}) to set the date back to TODAY()
  • - Use < & > to change date (by one day) and, all the corresponding data in Gallery1 will change automatically (reason: it will refer to the Toggle.Default to fire every time the date is changed!)…This is important and a very user-friendly action. Simple and instant.

Teacher - Marking Student Attendance StatusTeacher - Marking Student Attendance Status

 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:

  • - There is no data for THAT DAY & THAT GRADE (use CountRows = 0). Once data is saved and data is contained for THAT DAY & THAT GRAEDE, the SAVE

ICON will disappear, leaving the teacher to depend on Toggle to UPDATE attendance status.

  • - Toggle has NO ACTION when no data for THAT DAY & THAT GRADE. But when DATA is available on THAT date & THAT GRADE, it will start to FIRE every time it is changed.

 

"Click" to Save"Click" to Save   Saving in Process; GIF AnimationSaving in Process; GIF Animation   Student Counter updated, "Save" Icon disappears (Now - in Update mode)Student Counter updated, "Save" Icon disappears (Now - in Update mode)

 

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…

 

 

Comments

*This post is locked for comments

  • shree Profile Picture shree
    Posted at
    Apps with Batch Saving & Single Record Updating [Part 2]

    Atleast you can put a link "Next" and "Back" for Part 3 and Part 1. The article is vaguely written.

  • MShareef Profile Picture MShareef
    Posted at
    Apps with Batch Saving & Single Record Updating [Part 2]

    Wonderful article

  • hpkeong Profile Picture hpkeong 2,944
    Posted at
    Apps with Batch Saving & Single Record Updating [Part 2]

    Much to learn from Microsoft and Teams.

  • Audrie101 Profile Picture Audrie101
    Posted at
    Apps with Batch Saving & Single Record Updating [Part 2]

    What a cool UI you created! You're a master at formulas too! WOW!