6 Replies Latest reply on Sep 10, 2013 2:35 PM by CekariYH

    Trapp if a user tries to delete a record ?

    CekariYH

      Title

      Trapp if a user tries to delete a record ?

      Post

           Is there anyway to check if a delete record request is made to run a script or in a script by a function?

           To prevent the delete for some default records but allow for others marked unlocked in a field.

        • 1. Re: Trapp if a user tries to delete a record ?
          philmodjunk

               You can set access permissions--such as allowing some records to be deleted and not others via record level access control.See "Editing record access privileges" in FileMaker Help and check out this particular sub section: "Entering a formula for limiting access on a record-by-record basis" for a description of how to set this up.

               Another option is to use FileMaker Advanced to set up a custom menu set for the layout. In such a custom menu set, the Delete Record menu option can run a script you design instead of the Standard Delete Record action and thus your script can check to see if Deleting the record is permitted.

               A third option (if you don't have FileMaker Advanced) is to set up access permissions in Manage Security so that no records may be deleted. Then you add a button that performs a script (set to run with "full access privileges") that deletes the record if it has not been "locked".

          • 2. Re: Trapp if a user tries to delete a record ?
            CekariYH

                 Ok:

                 

            You can set access permissions--such as allowing some records to be deleted and not others via record level access control.See "Editing record access privileges" in FileMaker Help and check out this particular sub section: "Entering a formula for limiting access on a record-by-record basis" for a description of how to set this up.

                 1. Seems to be a tedious workaround for a simple request and I'm not ready to use that yet in this early stage of building/testing etc,  but will for sure later on.

                  

                 

            Another option is to use FileMaker Advanced to set up a custom menu set for the layout. In such a custom menu set, the Delete Record menu option can run a script you design instead of the Standard Delete Record action and thus your script can check to see if Deleting the record is permitted.

                 2. Yes, was thinking about that too, but how about the default Toolbar Delete button then? I'm trying to use as much as possible of the original menus and toolbar options as I can, why reinvent the wheel? Wish there was a way to trigger the delete request however it's done... <sigh>  Looks like that I have to send yet another "feature" request for the FMP staff....

                  

                 

            A third option (if you don't have FileMaker Advanced) is to set up access permissions in Manage Security so that no records may be deleted. Then you add a button that performs a script (set to run with "full access privileges") that deletes the record if it has not been "locked".

                 3. See 1.

                  

                 Hmmm, so no "in code" script or function to run a test before a delete is executed/allowed then...

                 How do you then prevent  a deletion of a parent when the parent has childs if you allow non-child parents to be deleted... or when a record is marked as protected... and I was hoping that a script using the IsEmpty ( Child::ForeignKey ) = True or If (Table::ProtectedField) = True etc etc in a script... without using options 1, 2, or 3.

                  

                 Sorry if I seems that I'm whining but FMP seems to lack some obvious (to me) options in some areas. Lot of workarounds but not the real thing is the impression I get when searching/reading the forums

            • 3. Re: Trapp if a user tries to delete a record ?
              philmodjunk

                   2) Hiding and locking the tool bar keeps the user from accessing delete record in the Records menu but the keyboard short cut for deleting a record will still work. Hence 1 as a suggestion if you don't have FileMaker Advanced and it's not as difficult to set up as you might think.

                   I myself have suggested that they should add a script trigger for the delete record action. Have used that to good effect in other applications.

                   How do you then prevent  a deletion of a parent when the parent has childs if you allow non-child parents to be deleted...

                   Sorry, but that doesn't quite make sense--maybe messed up in translation? Cascading deletes can be enabled so that deleting a parent also deletes related child records but that doesn't quite seem to be what you are asking here.

                   There is an alternative approach for keeping "deletes" safe. It also makes it easy to "undo" a delete. Instead of actually deleting the record from the table, you set a field to show it's "deleted status". I think we've discussed that method earlier. But keep it in mind as then you simply change the status field back from "deleted" to undo a record delete.

              • 4. Re: Trapp if a user tries to delete a record ?
                CekariYH

                      

                     First, I'm sorry if I sounded harsh before.

                     It wasn't easy to find the "set access permissions" etc, in the help in my language and then when I tried to switch the OS to English to get FMP12A in English there was no help at all??? go figure :-)

                      

                     Well, I got my 3 ordered FMP12A books today and after some reading and testing it worked out very well, would even say clever and configure-able. 

                     Still want that event trigger for an OnDeleteRecordRequest event for speeding up testing etc. and to get some clean code to better see the the whole picture, I even suggested it to FMP-staff, so perhaps in the future.

                      

                     -Now, how do I switch user "on the fly" or do one have to close the file first and reopen it (as I do now)?

                      

                     

                          "How do you then prevent  a deletion of a parent when the parent has childes if you allow non-child parents to be deleted…"

                     

                          Sorry, but that doesn't quite make sense--maybe messed up in translation? Cascading deletes can be enabled so that deleting a parent also deletes related child records but that doesn't quite seem to be what you are asking here.

                      To clarify,I build special solutions that can't be found anywhere, mostly, so they are often easy in mind but complicated to do in code, and also to be foolproof against average users as fools are so genius. ;-) 

                      

                     Then: (hidden can be used instead of delete)

                     1. A parent with children can exist just because of the children and if there are no children the existence of the parent is of no use, and so you can delete the parent.

                     2. The parent could be of no use but the children can still be used with an another parent or parents so they should keep existing even if the original parent is gone.

                     3. The children are of no further use and can be deleted but the parent is still useful so lets keep it. 

                     4. Both the parent and it's children are of no use, then delete them all.

                      

                     (that sounded ugly if used elsewhere, but you get the point)

                      

                     Many thanks for your struggles to keep me alert :-)

                • 5. Re: Trapp if a user tries to delete a record ?
                  philmodjunk
                       

                            -Now, how do I switch user "on the fly"

                       There's a script step: Re-login that opens the password dialog and let's you select a new account name and password--very useful when testing different privilege sets.

                       

                            Then: (hidden can be used instead of delete)...

                       Yes, but what is the question? This can all be handled with scripting and while we both would like a script trigger for record deletes, it's not an option and we do have alternatives that will work for this. Long before we had other such options, I just put a very visible button labeled "delete" on the layout with my own script and set password permissions to not allow the user to delete records except by the delete button.

                  • 6. Re: Trapp if a user tries to delete a record ?
                    CekariYH
                         

                    There's a script step: Re-login that opens the password dialog and let's you select a new account name and password--very useful when testing different privilege sets.

                    Ah, missed that one... done.

                          

                         

                    Yes, but what is the question?... 

                    That was just to clarify when you said "Sorry, but that doesn't quite make sense--"  :-)