Validate delete

jimmyfjimmyf Member Posts: 104
What is the best way programatically to stop a user deleting a record if certain conditions are met?
thanks

Comments

  • DenSterDenSter Member Posts: 8,304
    You would program this condition in the OnDelete trigger of the table. Mind you, that only works when someone is manually deleting records, and when DELETE is called from C/AL code with parameter TRUE. When DELETE is called with FALSE, it does not execute logic in the OnDelete trigger, so in that case you need to also add the condition to whatever process is deleting the record.
  • canadian_baconcanadian_bacon Member Posts: 91
    You can also do this on the OnGlobalDelete function in Codeunit 1. Put an error statement in there and log deletes (in the Change Log Setup) for whatever table to you want to control.

    Of course, this requires the change log granule.
  • DenSterDenSter Member Posts: 8,304
    "Certain conditions" usually apply to individual tables. I would always program conditions like that in those tables themselves. If you program codeunit 1 to handle exceptions for specific tables, you would always have to move individual tables with codeunit 1 when you do object maintenance. What kind of issues would come with that if you are in the middle of development for 35 tables, and only 2 of them are tested and approved? You would have to wait until development for all the other ones is done to move stuff out to production. That's asking for object conflicts in my opinion.

    It's very smart thing to do for global conditions though, I can definately see there's a lot of potential in that approach. Just not for conditions specific for individual tables.
  • canadian_baconcanadian_bacon Member Posts: 91
    Actually I meant that you would check for log deletes in change log setup table, not the codeunit.
  • SavatageSavatage Member Posts: 7,142
    Just a bit off topic - what percentage of customer's would you say get the change log granule?
    We for one don't.. Is this a sql thing or available in native too.
    Which version did it appear in?

    Sorry for the tangent & thanks.
  • canadian_baconcanadian_bacon Member Posts: 91
    I would say about 50% of our clients get it, maybe a bit less. Yes, it works for both native and SQL.
Sign In or Register to comment.