AL icon indicating copy to clipboard operation
AL copied to clipboard

Error during publish when EventSubscriber have parameter RecRef

Open fridrichovsky opened this issue 5 months ago • 2 comments

1. Describe the bug I have similar behavior as described in https://github.com/microsoft/AL/issues/7832. I can compile my code and everything looks good. Problem raise when I publish application to database (OnPrem server)

2. To Reproduce Steps to reproduce the behavior:

  1. Create new appliction
  2. Create new object
codeunit 55007 "Item Templ. Mgt. EH TRT"
{
    SingleInstance = true;

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Item Templ. Mgt.", OnInitFromTemplateOnBeforeValidateFields, '', false, false)]
    local procedure OnInitFromTemplateOnBeforeValidateFields(var FieldValidationList: List of [Integer]; var ItemTemplRecRef: RecordRef)
    begin

    end;
}
  1. Compile application
  2. Publish application to DB

3. Expected behavior Publish will be without problems

4. Actual behavior Publish-NavApp raise error:

One or more errors occurred. (Failure while emitting method. Object:'Codeunit "Item Templ. Mgt. EH TRT"' Method:'OnInitFromTemplateOnBeforeValidateFields(var List of [Integer], var RecordRef)' (Unexpected value 'Joker' of type 'Microsoft.Dynamics.Nav.CodeAnalysis.NavTypeKind')) Failure while emitting method. Object:'Codeunit "Item Templ. Mgt. EH TRT"' Method:'OnInitFromTemplateOnBeforeValidateFields(var List of [Integer], var RecordRef)' (Unexpected value 'Joker' of type 'Microsoft.Dynamics.Nav.CodeAnalysis.NavTypeKind') Unexpected value 'Joker' of type 'Microsoft.Dynamics.Nav.CodeAnalysis.NavTypeKind'

5. Versions:

  • AL Language: 15.2.1630495
  • Visual Studio Code: Version: 1.102.1 (user setup) Commit: 7adae6a56e34cb64d08899664b814cf620465925 Date: 2025-07-15T16:41:17.147Z Electron: 35.6.0 ElectronBuildId: 11847422 Chromium: 134.0.6998.205 Node.js: 22.15.1 V8: 13.4.114.21-electron.0 OS: Windows_NT x64 10.0.26100
  • Business Central: 26.3.36158.36321
  • Operating System:
    • [ x] Windows
    • [ ] Linux
    • [ ] MacOS

Final Checklist

Please remember to do the following:

  • [ x] Search the issue repository to ensure you are reporting a new issue

  • [ x] Reproduce the issue after disabling all extensions except the AL Language extension

  • [x ] Simplify your code around the issue to better isolate the problem

Internal work item: AB#595958

fridrichovsky avatar Jul 23 '25 13:07 fridrichovsky

Emit error, should be fixed

BazookaMusic avatar Aug 05 '25 07:08 BazookaMusic

Hello @BazookaMusic , I tested error on last version BC27 CU01 and error persist.

My code and error message:

##[error]One or more errors occurred. (Failure while emitting method. Object:'Codeunit "Item Templ. Mgt. EH TRT"' Method:'OnInitFromTemplateOnBeforeValidateFields(var List of [Integer], var RecordRef)' (Unexpected value 'Joker' of type 'Microsoft.Dynamics.Nav.CodeAnalysis.NavTypeKind')) Failure while emitting method. Object:'Codeunit "Item Templ. Mgt. EH TRT"' Method:'OnInitFromTemplateOnBeforeValidateFields(var List of [Integer], var RecordRef)' (Unexpected value 'Joker' of type 'Microsoft.Dynamics.Nav.CodeAnalysis.NavTypeKind') Unexpected value 'Joker' of type 'Microsoft.Dynamics.Nav.CodeAnalysis.NavTypeKind'

codeunit 55007 "Item Templ. Mgt. EH TRT"
{
    SingleInstance = true;

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Item Templ. Mgt.", OnInitFromTemplateOnBeforeValidateFields, '', false, false)]
    local procedure OnInitFromTemplateOnBeforeValidateFields(var FieldValidationList: List of [Integer]; var ItemTemplRecRef: RecordRef)
    var
        ItemTemplFldRef: FieldRef;
        I: Integer;

    begin
        for I := 1 to FieldValidationList.Count() do begin
            ItemTemplFldRef := ItemTemplRecRef.Field(FieldValidationList.Get(I));
            if ItemTemplFldRef.Type() = ItemTemplFldRef.Type::Boolean then begin
                if ItemTemplFldRef.Value() in ['Ano', 'Ja'] then
                    ItemTemplFldRef.Value := '1';
                if ItemTemplFldRef.Value() in ['Ne', 'Nein'] then
                    ItemTemplFldRef.Value := '0';
            end;
        end;
    end;

fridrichovsky avatar Nov 11 '25 07:11 fridrichovsky