Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: "Word Template".AddUnrelatedTable method not working as expected #3105

Closed
1 task done
zeande opened this issue Feb 26, 2025 · 2 comments · Fixed by #3135
Closed
1 task done

[Bug]: "Word Template".AddUnrelatedTable method not working as expected #3105

zeande opened this issue Feb 26, 2025 · 2 comments · Fixed by #3135
Labels
Approved The issue is approved Integration GitHub request for Integration area

Comments

@zeande
Copy link
Contributor

zeande commented Feb 26, 2025

Describe the issue

The method AddUnrelatedTable from the Word Template codeunit has the following 2 issues, which I don't believe are by design:

  1. The method does not return the result from the implementation codeunit. This results in callers always thinking that the method failed to add the record in the table.
  2. In the implementation, the specified WordTemplateCode does not actually get set on the new "Word Templates Related Table" record. This results in the related table being unusable in the Word Template.

Expected behavior

  • The method should return true if the record was added; otherwise, false. (which would match the method documentation)
  • The created "Word Template Related Table" record should contain the Word Template Code that was given to the method.

Steps to reproduce

The following code demonstrates the issue and is reproducible. This will only work in the context of a Microsoft App since the problematic table is internal. One can use recordrefs to observe the same result.

    local procedure IssueRepro()
    var
        WordTemplateRec: Record "Word Template";
        CompanyInformation: Record "Company Information";
        WordTemplatesRelatedTable: Record "Word Templates Related Table"; // (Access = Internal)
        WordTemplate: Codeunit "Word Template";
        Result: Boolean;
        MyTemplateCodeLbl: Label 'MY TEMPLATE', Locked = true;
        MyTemplateNameLbl: Label 'My Template', Locked = true;
    begin
        WordTemplateRec.Init();
        WordTemplateRec.Code := MyTemplateCodeLbl;
        WordTemplateRec.Name := MyTemplateNameLbl;
        WordTemplateRec."Table ID" := Database::Microsoft.Sales.Customer.Customer;
        WordTemplateRec.Insert(true);

        CompanyInformation.Get();
        Result := WordTemplate.AddUnrelatedTable(WordTemplateRec.Code, 'COMPA', Database::"Company Information", CompanyInformation.SystemId);
        // Result should be true, but the method always returns false

        WordTemplatesRelatedTable.Get(WordTemplateRec.Code, Database::"Company Information");
        // This call will currently always fail because the Code is empty on the created record.
        // This *could* be by design, but I have a hard time believing that. As is, the created record
        // is never usable by the word template (nor does it appear in the UI since Code is empty).
    end;

Additional context

Further evidence that this behavior is not part of the original design is that in the initial check for IsRelatedTableCodeAndIdUnique, the WordTemplateCode is used as a filter on the Code field.

Image

Image

I will provide a fix for a bug

  • I will provide a fix for a bug
@JesperSchulz JesperSchulz added Integration GitHub request for Integration area Follow Up The issue has an open question and must be followed up on labels Feb 28, 2025
@JesperSchulz
Copy link
Contributor

I'd like @stkillen to take a look at this one. Stay tuned 😊

@stkillen stkillen added Approved The issue is approved and removed Follow Up The issue has an open question and must be followed up on labels Mar 3, 2025
@stkillen
Copy link
Contributor

stkillen commented Mar 3, 2025

Approved. As you point out, the facade should return the result from the implementation codeunit and the code should be set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Approved The issue is approved Integration GitHub request for Integration area
Projects
None yet
3 participants