Form - OnDeleteRecord Trigger

Dneal
Dneal Member Posts: 103
Hi all,

I seem to be stuck on something and hoping someone can help.

I have code put in the Form-OnDeleteRecord and it runs fine.

Form.RUNMODAL(50017,REC);

The purpose is so when the user deletes a CODE in a record they must choose a new CODE to replace it. They have duplicate Ship-to Address codes.

So when the form runs from the OnDeleteRecord and the user chooses CANCEL the record gets delete. I have the updating code sitting in the OK button.

I tried to use:
IF FORM.RUNMODAL(50017,REC) = ACTION::CANCEL THEN
EXIT;

However this doesn't stop the record from getting deleted. Does anyone know how I can program this properly?

I hope this is clear, any help would be appreciated.

Thank you,

Dneal

Comments

  • bbrown
    bbrown Member Posts: 3,268
    Use EXIT(FALSE);


    However, prompting for user input within a transaction is very bad idea.
    There are no bugs - only undocumented features.
  • kuju
    kuju Member, Microsoft Employee Posts: 62
    Dneal,

    Like bbrown mentioned maybe it's a better idea to create a
    - DeleteFunction on the table.
    - On the form set the "DeleteAllowed" to false.
    - Create Menubutton on form with DeleteFunction in AL (F4)

    In this way:
    -you're not interrupting a transaction
    -You're not writing code on the form (In the new 5.0 client writing Business logic will probably not be possible anymore)
    - You can call the deletefunction from several forms or the deletetrigger on the table

    K.
    Dynamics Rules!
  • Dneal
    Dneal Member Posts: 103
    Thank you both for your help. I will be using both suggestions.

    Dneal
  • kriki
    kriki Member, Moderator Posts: 9,127
    bbrown wrote:
    Use EXIT(FALSE);


    However, prompting for user input within a transaction is very bad idea.
    At the moment of the RUNMODAL of the form, the user is NOT in a transaction, because if he is in a transaction, Navision would give an error with a VERY big message.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!