Options

Global variable in onDelete trigger

weneedweneed Member Posts: 81
I need to delete a set of record in a table (Table1) applying filter. For each record in this table there may be other records in a secondary table (Table2).
In onDelete trigger there is code to cascade delete all record related in Table2. But in this code there is a confirm to ask user every time a record was deleted.
I want use trigger to delete related record but i need skip confirm. So I've create a global variable, hideConfirm, to skip this confirm and a procedure to set this variable.
This is code:

trigger OnDelete()
begin
if not HideConfirm then
if not CONFIRM(QstDeleteSchema, FALSE) then
exit;

Table2.SETRANGE(FieldFilter, FieldFilterValue);
Table2.DELETEALL;


end;

procedure SetHideConfirm(parHideConfirm: Boolean)
var

begin
HideConfirm := parHideConfirm
end;


This was main code that execute

RecordsetTable.SetHideConfirm(true);
RecordsetTable.DELETEALL(TRUE);

But when execute OnDelete trigger HideConfirm global variable was false...

Why?

Answers

  • Options
    vaprogvaprog Member Posts: 1,118
    Try using DELETE(TRUE) looping through the record set yourself. If the Trigger is to be used (requested by using DELETE(TRUE)) then the system needs to delete the records one by one anyway.
  • Options
    weneedweneed Member Posts: 81
    But question is: why variable HideConfirm not save value if RecordsetTable instance is same?
Sign In or Register to comment.