in this lesson we will see how to allow deleting a record
in the database and we're going to do this again
on the Contact Detail screen. So we want to add
a third button here to our form to
delete this contact, so let me just drag-and-drop
and
in the Button Label
we're going to write down 'Delete'. And now I need to bind this button to a
Screen Action
and I'm going to use a shortcut. I'm going to double-click the Delete button
and this creates the Delete Action
on this Delete Action
we will need to use another
Entity Action, this is the Delete Entity Action
which deletes the record. It receives as an input parameter
the ID of the contact in this case to be deleted so
here in the Data tab Delete Contact, here we have it
and instead of receiving a record
as the other actions that be used this Delete Contact
actually receives the Contact ID. Okay
and once we delete this contact we want to redirect the user back to the
contacts page
and again here I'm going to use another shortcut
drag-and-drop to Contacts screen on top of the End
and this creates a destination to the Contacts page
okay we're done, we just need to
do something here because this delete
action it doesn't make much sense to be
visible when we are creating a new contact so again
we're going to use the same condition we used for the UI If
so let me just copy-paste this to make it quicker
CTRL+C and we're going to use this condition
in a property of the button which is the 'Visible' property
this is again an expression that returns True or False
and when it is True the button is visible, the button is rendered
in the page make. When it is False it is not rendered
if this expression is set with, let me just use CTRL+V here
with ContactId = NullIdentifier()
this means that well actually this is not the condition that we want
because I only want the button to be visible when I have the ContactId
filled-in, so actually instead of using the
equal here I'm going to use the
not equal, the difference operator
so when my ContactId is different from Null, when its not
creating a new contact then show
the delete button. Okay we're done, let's test this in a browser
Okay let's
try to delete here a contact, let's say that we want to delete
well let's delete John Doe that we created in the previous lesson
and delete
and we no longer have John Doe, so it seems
it seems to be working. Let me just
try to do this again and go over the page life cycle
so that we're sure that we know what's going. Let me just
open here Maria. What happens when we
press this delete button is that
again a request is made to the server the
delete screen action gets executed
and on this Delete Screen Action we are
using the the Delete
the Delete Entity Action
which in turn is going to the database
is finding
Maria's contact here
and it is deleting it from the database
and once these this Screen Action
and we are actually using that
Destination so we are actually redirecting to the Contacts page
and again the Preparation
is executed and on that Preparation we are
again fetching the contacts
from the database and then those contacts
are returned, are rendered one by one
during the server-side render stage and
then this is sent back, the response
is sent back to be shown here in the browser
and when these responses are send back to the browser
we will no longer find Maria on
our contact list. That's it.