[Bug]: codeunit 5510 "Production Journal Mgt" - SetTemplateAndBatchName
Describe the issue
There is a bug in codeunit 5510 "Production Journal Mgt" in procedure SetTemplateAndBatchName.
ItemJnlTemplate.SetRange("Page ID", PageID);
ItemJnlTemplate.SetRange(Recurring, false);
ItemJnlTemplate.SetRange(Type, PageTemplate);
if not ItemJnlTemplate.FindFirst() then begin
ItemJnlTemplate.Init();
ItemJnlTemplate.Recurring := false;
ItemJnlTemplate.Validate(Type, PageTemplate);
ItemJnlTemplate.Validate("Page ID"); // This should validate PageID
When the record is inserted it is missing page id. The next time the same procedure is called it will still not find the record (because of the filters), but try to insert the same record it has already inserted.
Expected behavior
If a record with the page id is missing, it should insert a record with the same page id, and not 0.
Steps to reproduce
View the example, it's a straight forward issue.
Additional context
No response
I will provide a fix for a bug
- [x] I will provide a fix for a bug
:robot: AI triage completed. Product group, please validate the triage report (Microsoft internal access only, use Ctrl+Click to open in new tab).
Was this triage helpful? React with :thumbsup: or :thumbsdown: on this comment to provide feedback.
It is assumed here that after Init() + Validate(Type), the "Page ID" field is still 0, but It is not. Here's why:
Validate(Type, PageTemplate) fires the OnAfterValidateType event on Table 82. The event subscriber in MfgItemJournalMgt.Codeunit.al handles "Prod. Order" and directly assigns "Page ID" := Page::"Production Journal". When Validate("Page ID") is then called without a second parameter, AL validates with the current field value — which is already Page::"Production Journal" (non-zero). The "Page ID" OnValidate trigger in ItemJournalTemplate.Table.al only acts when "Page ID" = 0. The record is inserted with the correct Page ID, matching the filter. On subsequent calls, FindFirst() succeeds and no duplicate insert is attempted.
I would say all good here.
It is assumed here that after Init() + Validate(Type), the "Page ID" field is still 0, but It is not. Here's why:
Validate(Type, PageTemplate) fires the OnAfterValidateType event on Table 82. The event subscriber in MfgItemJournalMgt.Codeunit.al handles "Prod. Order" and directly assigns "Page ID" := Page::"Production Journal". When Validate("Page ID") is then called without a second parameter, AL validates with the current field value — which is already Page::"Production Journal" (non-zero). The "Page ID" OnValidate trigger in ItemJournalTemplate.Table.al only acts when "Page ID" = 0. The record is inserted with the correct Page ID, matching the filter. On subsequent calls, FindFirst() succeeds and no duplicate insert is attempted.
I would say all good here.
If you use the event to override PageID, it will not be correct. Would it be a problem to change to Validate("Page ID", PageID)? Then it would work for both? Or check whether PageID is not the default ID and when validate with PageID?
Yes, Validate("Page ID", PageID) could work.
@auzhhv - Could you please proceed with the fix ?
Håkon Hvitsten (@auzhhv) - Could you please proceed with the fix ?
Sorry for the late reply. I will look at it this weekend.