Parhase Header Delete

FommoFommo Member Posts: 138
Hi there

I have a mysterious (for me anyway) problem. I'm doing an integration with NAV from a external system. The external system sends messages to NAV for posting invoices and such things.
Everything works out fine, except for canceling invoices.

I use the following code:
  IF (PurchHeader.GET(PurchHeader."Document Type"::Invoice, C00)) THEN BEGIN
        // Delete the invoice
        PurchHeader.DELETE(TRUE);

When I step through "Purchase Header".OnDelete everything seems to go fine, but when I come back to the code in my example I get an error saying that the invoice was not found. And then the execution breaks.

The result is that the invoice is deleted as intentioned, but I can't send any verification to the external system as I can't execute the code below the deletion.
Does anyone know what is wrong, or am I just stupid? ](*,) [/code]

Comments

  • krikikriki Member, Moderator Posts: 9,110
    Check with the debugger where the error occurs. Probably it is some trigger that does a get/find on the header that has just been deleted.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • FommoFommo Member Posts: 138
    kriki wrote:
    Check with the debugger where the error occurs. Probably it is some trigger that does a get/find on the header that has just been deleted.

    Well, I've gone through the code with the debugger and the strange thing is that OnDelete is ending normally, it execute every line in it as it should, but then when I press F8 once more to go back to the call for PurchHeader.DELETE(TRUE) I get a "Break on error" message and the execution ends pointing on that very PurchHeader.DELETE(TRUE) line.

    So I guess that something happens between the ending of OnDelete and the jump back to the call, something that I'm npt allowed to see and that triggers the error.
    Do you have idea what it can be, since I can't trace it deeper down with my developer license? :-s
  • ssissi Member Posts: 39
    I've seen that error when deleting a record in code on a form and that record is currently being displayed on the form. When the system finishes executing the code, it refreshes the screen and tries to read the record that was just deleted. Your post doesn't specify where your delete code is so I don't know if this is relevant.
  • jorgitojorgito Member Posts: 115
    Hi all.

    I have the same problem as described by Fommo and ssi.

    From the General Journal form, I open a modal form that deletes one of the original Gen. Journal Lines and replaces it with new Lines. The above code is executed at the OnPush trigger of the OK button of the Modal Form.

    When the modal form closes, I get an error that the (deleted) line does not exist. I close the error window and the new lines appear normally. Everything works fine, except for the error message that the (old and deleted) line does not exist.

    How can I overcome this problem?

    Thanks a lot
    Jorgito
  • kapamaroukapamarou Member Posts: 1,152
    We would need to see your code...

    What most often helps is either passing your record as a var parameter or calling CurrForm.UPDATE(FALSE) after your modal form returns...
Sign In or Register to comment.