Here is the code:I have two tables 1) Department 2) Channel Department
All the departments are linked with Channel Department in other words Channel Department is child table of Department.
So when i delete any department from Department table it doesn't prompts me that a particular department has a association in Channel Department; instead it deletes record from Department table only. Now in order to solve the above issue i have written few lines of code in OnDelete trigger that will delete departments from Channel Department as well.
ChannelDepartment.SETRANGE("Department Code","Department Code"); ChannelDepartment.DELETEALL;
IF CONFIRM(ConfirmDelete,TRUE) THEN BEGIN ChannelDepartment.SETRANGE("Department Code","Department Code"); ChannelDepartment.DELETEALL; END
Comments
That is because the Delete-trigger of the Department-table is still executing properly if you answer NO.
Try this code:
If you have scenario's where you do not want Lines deleted if they have been updated with some values then:
In the lines or header OnDelete Trigger put in the test fields, like in the Sales Line and Sales Header
Header
TESTFIELD(Closed,TRUE);
Lines OnDelete Trigger Code
TESTFIELD("Payment Received",FALSE);
TESTFIELD("Sales Invoice No.",'');
Then as Luc wrote
Header OnDelete trigger Code
// This will stop the header being deleted if not Closed = True
TESTFIELD(Closed,TRUE);
IF CONFIRM(ConfirmDelete,TRUE) THEN BEGIN
ChannelDepartment.SETRANGE("Department Code","Department Code");
ChannelDepartment.DELETEALL(TRUE);
END ELSE
ERROR('');
By adding the Testfield and the (TRUE) to the ChannelDepartment.DELETEALL: it will run the OnDelete Code and stop the deletion of Active records that have been actioned
Mobile: +44(0)7854 842801
Email: david.cox@adeptris.com
Twitter: https://twitter.com/Adeptris
Website: http://www.adeptris.com
aahan that means else block will stop the tigger in case of NO to message box.
David thanks for your idea; I think i will be coming on that task after few weeks. So by then i will have problem i will contact you up..
Its nice to have supportive and knowledgeable people like you at this forum.
Take Care,