How To: Adding Delete Links

There are two functions for deleting records from a Xephr Screen Entity.  The one that you use depends on whether you are trying to delete all records on the screen or a single record.

Delete Functions & When to Use Them

Delete();  

If the screen displays one record only or has one master block that displays a single record with one or more detail blocks that display one or more records, and you wish to delete the record in the master block and its detail blocks, then you should use this function.  This function will delete the data on any block on the screen that has the Deletable property set to true.  You can place this function outside of the block from which you wish to delete data as if affects all of the records displayed on the screen for which the block is set to Deletable.  A pop-up dialog box is displayed when the delete is successful and the screen is refreshed after this function is called.

In addition, the NO_SUCCESS_DIALOG parameter can be passed to this function to suppress the pop-up dialog box when the delete is successful.

DeleteThisRow();

If the screen displays multiple records or you only wish to delete a single record from the block but no other records on the screen, then you should use this function.  This function needs to be called from a field in the same block as the record that you are deleting.  A pop-up dialog box is displayed when the delete is successful and the screen is refreshed after this function is called.

In addition, the NO_SUCCESS_DIALOG parameter can be passed to this function to suppress the pop-up dialog box when the delete is successful.

ResetRow();

This function is used when a block contains new rows and the user may begin to enter a new record but then decides against it.  The function clears out the fields in the row and resets the row status to be unchanged so that when the Save function is called, the runtime will not attempt to save the now blank record to the database as a new record.  The screen does not refresh when this function is called.

Confirming and Saving before Delete

Often you will want to have the user confirm that they want to delete the record before actually deleting the record.  In addition, the delete function does not perform a save of any changes on the screen before performing the delete.  The code that you put on the Delete link should reflect any additional actions you want taken before the delete is called.

In the following example code, we are adding a delete link for a screen where we wish to first we delete a single record from the block but no other records on the screen.

The code first confirms the deletion of the record.  

Assuming that the user clicks Ok on the confirmation dialog, the code next checks to see if the record that is being deleted is a database record or a new record that the user is in the process of entering.  

If the record is a database record, the code saves the changes on the screen in case any other changes were made (and does not show the success dialog) and then if the save is successful, performs the delete without showing the success dialog.  The screen is refreshed.

If the record is a new record, then the code simply clears the new record and resets the row status to unchanged.

var agree = confirm('Delete this Record?');

if (agree)
 {if (RowExists())
     {Save(NO_SUCCESS_DIALOG);
      if(lastResult)

           {DeleteThisRow(NO_SUCCESS_DIALOG);}

        }

     else

       {ResetRow();}

    }

In this following example code, we are adding a delete link for a screen where we only display one record at a time.

The code first confirms the deletion of the record.  Assuming that the user clicks Ok on the confirmation dialog, the code performs the delete, showing the success dialog.  The screen is refreshed.

var agree = confirm('Delete this Record?');

if (agree)
{Delete();}

Steps for Creating a Delete link

  1. In the Explorer, find the entity and then the block to which you wish to add the delete link.  

  1. Right click on the block.

  2. Select Create > Label.

  3. The Adding Labels to Block wizard opens.

  4. Click the Add button.

  5. In the added field, enter DELETE.

  6. Press the Add Fields button.

  7. The Delete label is added to the block and is displayed in green.

  8. Press the [Save] button in the Main Toolbar.

  9. Click on the Delete label in the Explorer and display the property sheet.

  10. In the Hyperlink To property, enter the appropriate delete function and additional code, as in the examples above.

  11. Set the Hyperlink Scripted property to true.

  12. In the Contents property, enter the text that you want displayed as the link.

  13. Press the [Save] button in the Main Toolbar.