In the previous mission, we re-purposed the New Car screen to also be an edit car screen, and then we made it accessible by clicking a car in the cars list

In this mission, we are going to add a delete button to the screen so a user has the option of removing a car. 

Create Delete Button

1. Customize the New / Edit Car screen.

2. Drag a button object into secButtons and put it to the left of the Save button.

3. Change the new button's text to “Delete”.

4. Give the new button the Delete icon

5. Change the button Background Color to Secondary, then Save the screen.

Add Actions to Delete Button

The action you’re about to use is called Delete Records from Table - note the plural on "Records". That’s right - this action has the power to delete all the records from your table - which you definitely don’t want to do by accident! Thus, it's important to properly set up the conditions on how to delete from the table.

Warning: Deleting a record from a table can be tricky, and it’s an action you want to make sure you do correctly. 

1. Select down arrow ( ▼ ) on the Delete button and choose its Click event.

2. Add the action Delete Records from Table

3. For Select a Table Name, choose the table Cars. This is the table we want to delete from.

4. Beside Delete Records Where, click the Open Criteria Builder button.

Note: The Criteria Builder is used to help pinpoint what you want to delete from the table.

5. Click Add a condition.

6. In the first dropdown on the first line, you will see all the records in the Cars table. choose RecordID. This tells Method to cycle through the entire Cars table looking ONLY at the RecordID field. But what is it looking for? To answer that question, we’ll have to set up a Comparison and a second value to compare to. We want the app to find the record in the table that has the same RecordID as the one chosen in the grid.

7. For the next dropdown (used for comparison), keep the default of Is Equal.

8. For the third dropdown (value to compare to), search for and select Screen Active Record ID.

Note: A Screen Active Record ID is best explained by thinking about it in terms of caching. If you’ve filled in a form on a website and submitted it, then hit the back button, you see how the fields are still populated by the information you wrote down. That’s sort of how a Screen Active Record ID works. When you select a Record ID in the grid, Method saves that information in memory – the place it’s saved is considered the Screen Active Record ID. This means the 1st value will now be searching for the Active Record ID (which is the one you just clicked!)

Since the RecordID is unique, this action allows Method to isolate the individual record for deletion, rather than deleting every record in the table.

13. Select the Back link to exit the Criteria builder.

14. Include an Internal Note: “Delete car”, but don't close the Action Editor yet.

Delete Confirmation

We’re done with the functionality of the delete button, but since deleting can’t be undone, we might want to put one more step in: a confirmation message asking the user if they really meant to delete this record. You see this a lot in software packages - like when your word processor asks you if you’re sure you don’t want to save before closing. Let’s put one in here.

1. Click Add Action and search for and select Show Message.

2. For the Title, type in “Confirm Delete”.

3. For the Message: “Are you sure you want to delete this car?

4. For the Button(s), choose OK/Cancel (OK will compete the deletion, Cancel will close the message and ignore all subsequent actions).

5. Include an Internal Note: “Confirm Delete”.

Note: Now, as we know, actions are run in order - and we certainly don’t want to delete the record before asking for confirmation! 

6. Drag “Show Message action, by its line number, above “Delete Records From Table.

7. Close the Action Editor.

Going Back

Once the user has finished deleting a car, the screen should go back to the cars list. This should be familiar to you, because we did this in Mission 3 - 4

1. Add a third action and search for Call Routine action and select it.

2. The Select a Routine dropdown will list all the controls with events that have actions. The Back (Click) should already be selected.

3. Type in your Internal Notes, saying something like “Do Back's Click Event actions” so you know which action set it is calling.

6. Close the Action Editor and close Design Mode.

Now when the car is deleted, the app will return the user to the previous screen.

Coming up next...

In the next mission, we're going to do one more thing to the delete button. Notice how it's visible when you add a new car? Does that make sense? No. No it doesn't.

Previous Mission                         Next Mission

Did this answer your question?