i have been trying the code down below in the picture but it didnt work i am new at al coding and i cant seem to find good videos or site on the net (if u have good sites or youtube channels they might help too).
this is my try
this is my page
i have been trying the code down below in the picture but it didnt work i am new at al coding and i cant seem to find good videos or site on the net (if u have good sites or youtube channels they might help too).
this is my try
this is my page
procedure DeleteTimeSheet(TimeSheetCode: Code[20])
var
TimeSheetHeader: Record "Time Sheet Header";
begin
if TimeSheetHeader.Get(TimeSheetCode) then
TimeSheetHeader.Delete(true);
end;
A few notes and recommendations. The length of Code variables should be aligned with respective table fields which this code applies to. In this case, time sheet code in the Time Sheet Header table is Code[20], so it's a good idea to keep the variable the same length. This can protect your code from possible overflow runtime errors.
Variable name "TimeSheetHeader" is more human-readable than RecL950. Yes, the internal table ID of the timesheet header is 950, but I bet there is no developer who remembers all table numbers in BC. Best to name variables in a way that helps identify the object they reference.
Delete needs the primary key to be initialized, and it's a good idea to call it with the true parameter to invoke the OnDelete trigger. Code in the header trigger deletes linked timesheet lines and comments. TimeSheetHeader.Delete()
will not call the table trigger, and will leave orphan time sheet lines.
You can search for AL books, there are a few available. "Business Central Development Quick Start Guide" by Duilio Tacconi, is one recommendation. Or you can try "AL for Beginners" by Krzysztof Bialowas, it's free: http://www.mynavblog.com/2022/07/25/al-for-beginners-workbook-version-2-0/
like said the user Alexander Drogin, there's some issues with your code. In a "best practice" way and a logic way; the most important is the logic way. In you case you're trying to do the comparison with a null value inside the Record variable RecL950."No.". You have to filter this variable and do the find function in base to your requirements. Please check this article directly from Microsoft! https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/record/record-findfirst-method
(I've attached to you the case of the findfirst, please check also the other ones.)