Options

Stop Delete Process in onDelete() Trigger

elToritoelTorito Member Posts: 191
Hi,

I One Table in the onDelete Trigger i Have Code that checks
if a part of the record that i want to delete have a relation to a record in another table, if they are are relation, i would stop the delete Process.

But i don't know who.

Here my Code that not works:
myRecord.RESET;
myRecord.SETFILTER("myField",'myData');
IF myRecord.FIND('-') THEN BEGIN
  MESSAGE('Don't Delete Them');
  EXIT;
END ELSE BEGIN
  MESSAGE('ok, must delete');
END;

Thanks

PS: I think that the EXIT Command ist wrong for this way ?
(Oo)=*=(oO)

Comments

  • Options
    elToritoelTorito Member Posts: 191
    I'm Stupid ...
    It Must be ERROR and Not MESSAGE :P

    So it's right:
    myRecord.RESET;
    myRecord.SETFILTER("myField",'myData');
    IF myRecord.FIND('-') THEN BEGIN
      ERROR('Can't Delete Them');
    END;
    
    (Oo)=*=(oO)
  • Options
    s_vahagns_vahagn Member Posts: 19
    You must write EXIT(FALSE).
    DDE functions in Navision
  • Options
    elToritoelTorito Member Posts: 191
    s_vahagn wrote:
    You must write EXIT(FALSE).

    If i put EXIT(FALSE) it say may that :
    "A variable was expected"

    If i put only EXIT it's okay but does not exit.

    No i have it so, an it works:
    myRecord.RESET;
    myRecord.SETFILTER("myField",'=%1', "myVarForField");
    IF myRecord.FIND('-') THEN BEGIN
      IF CONFIRM('Would you delete it?') = FALSE THEN BEGIN
           ERROR('Not deleted');
        END;
      END;
    

    I Think that an EXIT an this position is more nice than the error message because, so the user must first press the confirm and second press the message thats say him that was not deleted, but if i put an EXIT there where ist the ERROR now, it delete me the record :( and EXIT(FALSE) would expected a variable ?

    Thanks.
    (Oo)=*=(oO)
  • Options
    ArhontisArhontis Member Posts: 667
    Hi,

    The "Variable Expected" is that the OnDelete trigger by definition has no return value.

    You can use
    ERROR('')
    
    which stops the transaction and doesn't displays any error.
  • Options
    elToritoelTorito Member Posts: 191
    Arhontis wrote:
    Hi,
    You can use
    ERROR('')
    
    which stops the transaction and doesn't displays any error.

    Thankkkkks :P
    (Oo)=*=(oO)
Sign In or Register to comment.