Business Central 2023 wave 2 (BC23): Using rich text (HTML) content in RDL layouts

Dynamics 365 Business Central

Hi, Readers.
When I opened SNS this morning, I saw some experts sharing that Microsoft has updated the following document.
Using rich text (HTML) content in RDL layouts:

If you’ve created a Rich Text content control, you can display the text on an RDL report. This means that you can display multi-line formatted text, emphasize important points, and have clickable hyperlinks.

Rich Text is stored as HTML within the database. In order to display the formatted HTML, you need to change the Placeholder Properties within your RDL.

https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-howto-rdl-report-layout?wt.mc_id=DX-MVP-5004336#using-rich-text-html-content-in-rdl-layouts

Thanks so much for sharing. So in this blog post I would like to briefly test it out.

The Rich Text feature in Business Central is designed to handle multimedia content, such as social media posts, email bodies, quick annotations, file contents, or any field that requires a mix of text, tables, links, and images. More details: Business Central 2023 wave 2 (BC23): Use the built-in rich text editor to enter data

Test video:

I hadn’t considered being able to print Rich Text before because it contains so many elements. Let me do a simple test.

First created a Rich Text feature on the Customer Card page using the code I introduced in Business Central 2023 wave 2 (BC23): Use the built-in rich text editor to enter data. And added some content.

Then create a very simple report. Display customer number, customer name and Rich Text content. The report layout type is rdlc.

Add an action to the customer card to run this report and print the current customer’s information.

As for the layout file, first add the required fields to the layout.

After adding the field to your report layout that contains the Rich Text, left-click on the field so that the <Expr> tag is highlighted.

Right-click on the highlighted <Expr> tag and select Placeholder Properties....

On the General tab, select HTML - Interpret HTML tags as style radio button. Then Select OK to close the Placeholder Properties window.

That’s all. Let’s print it.

Great.

PS: If it is not changed to HTML - Interpret HTML tags as style, the following text will be displayed when printing.

Of course this does not print all the information, as mentioned in the Microsoft documentation, there are limitations imposed by the SQL Reporting Engine as to what HTML markup elements are processed. This Microsoft Learn article states that the following tags will be processed:

Any other HTML markup tags will be ignored during report processing (for example, images and tables). If the HTML isn’t well formed, the placeholder will be rendered as plain text. Unfortunately things like font colors and emojis aren’t processed for your report layout.

Great, give it a try!!!😁

PS: If the HTML exceeds the size of the page, it will not trigger a page break and continue onto the next page. This means your HTML will be truncated.

Source Code: GitHub (Please note that the source code is for reference only, you can improve it according to your own needs)

tableextension 50112 CustomerExt extends Customer
{
    fields
    {
        field(50100; RichText; Blob)
        {
            Caption = 'Rich Text';
            DataClassification = CustomerContent;
        }
    }
}
pageextension 50100 CustomerCardExt extends "Customer Card"
{
    layout
    {
        addafter(General)
        {
            group(RichTextGroup)
            {
                Caption = 'Rich Text Group';
                field(RichText; RichTextVar)
                {
                    Caption = 'Rich Text';
                    MultiLine = true;
                    ExtendedDatatype = RichContent;
                    ApplicationArea = All;
                    trigger OnValidate()
                    begin
                        SetRichText();
                    end;
                }
            }
        }
    }

    actions
    {
        addafter(Contact)
        {
            action(PrintRichText)
            {
                Caption = 'Print Rich Text';
                ApplicationArea = All;
                Image = Print;
                Promoted = true;
                PromotedCategory = Process;

                trigger OnAction()
                begin
                    Report.Run(Report::"Rich Text Content", true, false, Rec);
                end;
            }
        }
    }
    var
        RichTextVar: Text;

    trigger OnAfterGetRecord()
    begin
        GetRichText();
    end;

    local procedure GetRichText()
    var
        RichTextInS: InStream;
    begin
        Rec.CalcFields(RichText);
        Rec.RichText.CreateInStream(RichTextInS, TextEncoding::UTF8);
        RichTextInS.Read(RichTextVar);
    end;

    local procedure SetRichText()
    var
        RichTextOutS: OutStream;
    begin
        Rec.RichText.CreateOutStream(RichTextOutS, TextEncoding::UTF8);
        RichTextOutS.Write(RichTextVar);
        Rec.Modify(true);
    end;
}

report 50111 "Rich Text Content"
{
    UsageCategory = ReportsAndAnalysis;
    ApplicationArea = All;
    DefaultRenderingLayout = RichTextContent;

    dataset
    {
        dataitem(Customer; Customer)
        {
            column(No_; "No.")
            {
            }
            column(Name; Name)
            {
            }
            column(RichTextVar; RichTextVar)
            {
            }

            trigger OnAfterGetRecord()
            var
                RichTextInS: InStream;
            begin
                Customer.CalcFields(RichText);
                Customer.RichText.CreateInStream(RichTextInS, TextEncoding::UTF8);
                RichTextInS.Read(RichTextVar);
            end;
        }
    }

    rendering
    {
        layout(RichTextContent)
        {
            Type = RDLC;
            LayoutFile = 'RichTextContent.rdl';
        }
    }

    var
        RichTextVar: Text;
}

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL