Form refresh issue after deleting current record on card

RoelofRoelof Member Posts: 377
I have a problem refreshing a salesOrder after deleting the current record. I created some custom functionality what is validating a field. If checked it will ask to delete the record. That works fine by doing a rec.delete(true). However the form itself is not refreshing. I tried to fix that by adding some code in the OnAfterValidate trigger of this field on the form as: CurrForm.Update() (used true or false, both didn't work). But whatever I try nothing seems to work. If I then close the form I receive an error that says: 'Sales Header does not exist', with the document type and No. of the record I just deleted. Is there any trick how to overcome this problem?
Roelof de Jonghttp://www.wye.com

Comments

  • SavatageSavatage Member Posts: 7,142
    So you are saying you have added a checkbox to the sales header & when checked it deletes the header?

    Why not hit F4? or use sendkeys on check of the box to execute F4?
  • RoelofRoelof Member Posts: 377
    This is some custom code with some conditions what is triggering deleting the record.
    I wish I just could use the F4 button.
    But...any work around? I'm stuck.
    Roelof de Jonghttp://www.wye.com
  • dansdans Member Posts: 148
    If you can't use the F4, why not use a button that triggers the custom code and delete the record ?
    Microsoft Certified IT Professional for Microsoft Dynamics NAV

    Just a happy frood who knows where his towel is
  • RoelofRoelof Member Posts: 377
    It's not the F4 button. And the delete functionality works just fine. But.... when the record is deleted, the form is still showing the current record (believe me I tried everything possible to refresh the form, CurrForm.update(true), (False) etc... updating the OnNext, OnFind triggers of the form, everything, but the form is not refreshing and I'm receiving an error when I close the form or go to a next record as: 'Sales Header does not exist' with the information of the record I just deleted.
    Any suggestions anyone?
    Roelof de Jonghttp://www.wye.com
  • dansdans Member Posts: 148
    check if you have any filter on the form trigger.
    Microsoft Certified IT Professional for Microsoft Dynamics NAV

    Just a happy frood who knows where his towel is
  • SavatageSavatage Member Posts: 7,142
    You could always add RESET to clear all filters.
  • David_SingletonDavid_Singleton Member Posts: 5,479
    Roelof wrote:
    I have a problem refreshing a salesOrder after deleting the current record. I created some custom functionality what is validating a field. If checked it will ask to delete the record. That works fine by doing a rec.delete(true). However the form itself is not refreshing. I tried to fix that by adding some code in the OnAfterValidate trigger of this field on the form as: CurrForm.Update() (used true or false, both didn't work). But whatever I try nothing seems to work. If I then close the form I receive an error that says: 'Sales Header does not exist', with the document type and No. of the record I just deleted. Is there any trick how to overcome this problem?

    I think this is a bug.

    I had an almost similar issue many years ago. I did a lot of things to try to resolve it, but never could. Basically in the code I have it creates the record, does some work on the record then deletes it. Sometimes the refresh does not work, and if you close the form, then open again it gives a message that the record exists.

    A temporary table would solve the technical issue, but the created record needs to in the database, so that was not an option. In the end I had to add code to prevent the users form closing the form incorrectly or from being able to accidentally cause the error. And of course a lot of training. Even then, at least twice a year they have the problem, and the only fix is to either delete the users ZUP or design and save the form to lose the stored settings.

    If you ever work out the issue, please let us know, it will help me too.

    By the way, this started on 3.10 (native) then 4.00(native) then 5.00sp1(SQL). Each exe upgrade made it more stable, but even in 500sp1 there are still issues.
    David Singleton
  • RoelofRoelof Member Posts: 377
    Yes, this is weird. I'm not sure if it has something to do with filter-groups in the OnOpenForm trigger. I used 'Reset' and what not but that didn't help.
    I'll keep you posted if I come up with a solution.
    In the meanwhile if anyone has an idea, just let me know.
    Roelof de Jonghttp://www.wye.com
  • SavatageSavatage Member Posts: 7,142
    on the part of your code where you have rec.delete(true) have you thought about changing that code to sendkeys (f4) just to see if it behaves differently?
    viewtopic.php?f=5&t=25712
  • RoelofRoelof Member Posts: 377
    I solved the problem. Finally.
    What I did so far was making a call to my delete function from one of the SalesHeader table fields. Instead I'm making the call from the same field but on the SalesOrder form (header form). In the OnAfterValidate trigger I add the following code (I have done this before BUT without using the CurrPage.SAVERECORD line. That did the trick). Here is my code:

    //Start
    CurrPage.SAVERECORD;
    Cancel_Order;
    CurrPage.UPDATE;
    //End

    The CurrPage.SaveRecord was needed to overcome my problem. Don't ask me why.
    THe CurrPage.Update is refreshing the form. (I have used this before. It didn't work until now with this 'CurrPage.SaveRecord' line)
    Roelof de Jonghttp://www.wye.com
Sign In or Register to comment.