Backup build on F4 trigger in sales order header

aquariousaquarious Member Posts: 32
hi ,

I need some pointer and advice here. I would like to delete a sales order card , when i press F4 i want to build a trigger to save all the data in sales order header into another backup table before the sales order header data being deleted. The reason why i want to do this is to revise data that have been deleted. Is there anyone can help me in this problem? Thank you

Comments

  • kinekine Member Posts: 12,562
    OnDelete trigger on Sales table or on Form (if you want to backup only on deleting on this form). 8)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • DenSterDenSter Member Posts: 8,307
    There is a function to archive the sales order in standarde Navision that you could call from the OnDelete function. You'd have to create access to this form from the S&R menu though, but you can do this with available Navision functions.
  • aquariousaquarious Member Posts: 32
    Hi kine,

    I have block entire chunck of code in OnDelete and i create a new order in sales order header and then i press F4 to try to delete the sales order and my sales order that just created was deleted!! :shock:

    i thought that if i block entire chunk of code in the OnDelete in sales header it will not allow me to delete the sales order header that i have created ???

    please advice , thank you
  • aquariousaquarious Member Posts: 32
    Hi denster,

    The reason why i cant used the archived function is the user does not want to do so :( , else it would have save me a lot of efford to do so....please advice thank you.
  • kinekine Member Posts: 12,562
    aquarious wrote:
    Hi kine,

    I have block entire chunck of code in OnDelete and i create a new order in sales order header and then i press F4 to try to delete the sales order and my sales order that just created was deleted!! :shock:

    i thought that if i block entire chunk of code in the OnDelete in sales header it will not allow me to delete the sales order header that i have created ???

    please advice , thank you

    Yes, it was deleted, you must insert Error in this trigger, if you want to disallow deleting. If no code is in this trigger, record is deleted without any action (without deleting linked rows, dimensions etc.....!!!)

    Second point where disallow user to delete something is trigger OnDeleteRecord on form - if you return false, nothing is deleted, if you return true, all is OK and record is deleted with calling OnDelete trigger and after that trigger, recor is deleted.

    OnDelete trigger does not delete the record, it only do some additional actions. Record is deleted after this trigger if no error occured... 8)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • DenSterDenSter Member Posts: 8,307
    aquarious wrote:
    Hi denster,

    The reason why i cant used the archived function is the user does not want to do so :( , else it would have save me a lot of efford to do so....please advice thank you.
    First you say that you want a copy of the sales order in another table when a sales order is deleted, so I tell you how you can accomplish this virtually with standard Navision. Now you say that is not what the user wants... I must have misunderstood your initial question. :?

    If you block all the code in the OnDelete trigger, that means that you make the system not do anything, so there is nothing stopping the user from doing this. If you want to not allow deletion of sales orders, then you should program an error in that trigger and no user will ever be able to delete them anymore. :)

    What I have against programming data operations on the form is that you'd have to program the same thing on every form that accesses the table. If you program it in the table, it will automatically happen each time you put the table on a new form.
  • aquariousaquarious Member Posts: 32
    hi denster hi kine,

    I manage to fix this problem, my solution in OnDelete of Sales Header and Sales Line table i add in transferfields and insert code into the backup salesheader and salesline table.

    Thank you for advice again
Sign In or Register to comment.