Obviously, as with many things FileMaker, there can be several approaches.
One, possibly simplest, is to use the native security / privileges capabilities.
For any privilege set you wish to disallow the ability to delete a record in a given table, configure the Custom privileges of that table, specifying the "Delete" option to be "limited..." with the formula being something like:
getasboolean( deletable_flag )
where the field, deletable_flag, may be a boolean result calculation that takes into account all of the conditions that make a record deletable. If all the conditions are met, the result is '1' (deletable) otherwise, the result is '0' (not deletable). The formula above will allow the record to be deleted only if deletable_flag boolean true.
Or instead of using deletable_flag field, you could just use some othrer direct formula that produces a boolean result (1 always makes it deletable).
You must do this for each privilege group where deletion is to be prevented, but each privilege group could have a different formula determining conditions allowing the record to be deleted.
Also remember you must test this as a user of a privilege group other than [full access].
Security privileges are the most secure, but also the most work. Personally, I like using custom menus. Attach the a delete script to the Delete menu item and do your check in the script. Or, if in 12, make the appearance of the delete item conditional.
Nitpicking semantics note regarding "Or, if in 12, make the appearance of the delete item conditional":
- If using custom formatting on a delete button, Sarfaraz will still need the script to perform the check if deletes are not controlled by permissions -- even an invisible button can run a script if clicked by accident when you can't see it.
Another thought for Sarfaraz: if permissions are relied on but your running a delete script, don't set the script to run with full permissions, or they can't stop the delete when they should.
No, I'm referring to the ability to make a menu item appear or not by calculation in a custom menu. Not a button.