In the previous mission, we added a header to the New / Edit Car page so the user can go to the view contact screen.
You know what would be awesome? If we could select specific records in the grid and activate and deactivate them all at once. For those following along, this would be helpful to Valerie if she was sending multiple cars to maintenance at the same time - she could mark all of them as inactive all at once, rather than choosing individual records to change. So let’s set that up!
Add a Checkbox Column
1. Customize the Car List screen.
2. Select GridCar. In the properties panel on the right, expand the Columns header and click "Has a checkbox column".
And now each row has a checkbox column! That was easy. Now, let’s set up some buttons to do something with those checked rows. First we need a separate section for the buttons.
Add a New Section
1. Drag a new Section in and move it above secList.
2. Select the section and rename it secGridActions.
3. Change the padding to 1x EXCEPT FOR THE BOTTOM padding. We want it nice and close to the grid.
4. Select the section named secList and make sure the Top Padding to None.
Okay, the section is all set up. Now onto the button!
Add a Button
1. Drag a button object into secGridActions.
2. Right align the cell.
3. Select the button and change its text to “Deactivate”
4. Change the Text Size to Small.
5. Now, go into the Click event of your new Deactivate button.
Let's start plotting actions. This next action we’re going to use is called a loop. A loop is a way for Method to perform the same action a set number of times. In this particular case, we want to perform an action for each record the user has checked in the GridCar.
Add Action Loop Through Gird
1. Add the action Loop Through Grid.
2. For Select a grid, choose GridCar, the grid we will loop through.
3. Check the checkbox: Only select rows that are checked.
4. Make sure to add your Internal Note: “Loop through checked rows”.
Now this loop will go through each checked record in the grid. If you checked three rows, the loop will run three times: once for each row. Of course, we want it to run an action for each row, so let’s add that next.
Add Action Update Fields in Table
1. Hover over Loop Through Grid to see the ⊕ Add action below and click it.
2. Search for the action Update Fields in Table. Make sure it is indented underneath the Loop. What does this mean? For each record you check in the grid, it will apply the Update Fields in Table action!
3. Let's configure the action Update Fields in Table. For Select a table, choose Cars.
4. Click Open Criteria Builder.
5. Click ⊕ Add a condition.
6. For the first dropdown, choose RecordID.
7. The second dropdown should be the default setting: Equals.
8. For the third dropdown, scroll down and find, under Loop, RecordID. You can search for it to make it easier.
9. Select < Back to exit the Criteria Builder.
10. For Field(s) to update, search and select IsActive. The Update using this value should be Yes/No, and No. This means for each record checked in the grid, Method will set its IsActive field to “No”, effectively deactivating the record!
11. Make an Internal Note “Set checked records to inactive”.
Add Action Refresh Control
The last thing we should do is add a Refresh Control action. This won’t be in the loop, by default, but you’ll want to make sure it isn’t (do not indent it), because we only want Method to refresh the grid once: at the end of the loop. If it ends up in the loop, Method will refresh the grid every time we process a record - and that becomes a real pain for everyone involved.
1. Click ⊕ Add new action outside of the loop.
2. Search and add the action Refresh Control.
3. For Select a control, choose GridCar.
4. Make an Internal Note: “Refresh GridCar”.
Before closing, your Action Set should look like this:
Again, see how the action Refresh Control is not inside the Loop Through Grid action.
5. Close the Action Editor.
Add a New Button to Activate Selected Records
We now have a button designed to deactivate selected records, so logic would dictate we’d also want a button to reactivate selected records too, right? It certainly would, but here’s the thing: the process to create the Activate button is almost exactly the same as the process we just went through. So instead of walking you through all those steps again, here are the pertinent changes:
- A new button should have its Text set to “Activate”.
- When updating the IsActive field, set it to “Yes”.
All the other steps are exactly the same.
And that's it, you're done! Congratulations! Well done, you've completed all the missions. Feel free to further explore and add your own touches to the app, but I hope you get an idea on how app customization works. There is far more you can do with Method, and the best way to learn that is by experimenting.
Good luck, and thanks for joining me this whole time!