Skip to main content
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

EventSubscriber of Table "Email Item" OnBeforeGetBodyText not returning value

(0) ShareShare
ReportReport
Posted on by 384
Hello BC developers,
I m trying to modify word merging document dynamically. 
[EventSubscriber(ObjectType::Table, Database::"Email Item", 'OnBeforeGetBodyText', '', true, true)]

    local procedure OnBeforeGetBodyText(var EmailItem: Record "Email Item"; var Value: Text; var IsHandled: Boolean)
    var
        TempBlob: Codeunit "Temp Blob";
        FileManagement: Codeunit "File Management";
        BodyText: BigText;
        DataStream: InStream;
        BlobInStream: InStream;
        BodyOutStream: OutStream;
        MyHTML: Text;

        Attachments: Codeunit "Temp Blob List";
        AttachmentNames: List of [Text];

        NewBody: Text;
    begin

        MyHTML := '

Custom HTML

'; if not EmailItem.Body.HasValue() and not ((EmailItem."Body File Path" <> '')) then exit; if EmailItem."Body File Path" <> '' then begin //FileManagement.InstreamExportToServerFile(TempBlob, EmailItem."Body File Path"); //FileManagement.BLOBImport(TempBlob, EmailItem."Body File Path"); //TempBlob.CreateInStream(BlobInStream, TextEncoding::UTF8); //EmailItem.Body.CreateOutStream(BodyOutStream); //CopyStream(BodyOutStream, BlobInStream); end; if EmailItem."Plaintext Formatted" then begin EmailItem.Body.CreateInStream(DataStream, TextEncoding::UTF8); BodyText.Read(DataStream); BodyText.GetSubText(Value, 1); end else begin // EmailItem.Body.CreateInStream(DataStream, TextEncoding::UTF8); // DataStream.Read(Value); Clear(Value); EmailItem.Calcfields(Body); If EmailItem.Body.HasValue() then begin EmailItem.Body.CreateInStream(DataStream); DataStream.Read(Value); end; end; Value := MyHTML Value; IsHandled := true; End;
subscribing above method of "Email Item" table is not running nothing in BODY field. Following is the EMAIL ITEM.DAT file
[Scope('OnPrem')]
    procedure GetBodyText() Value: Text
    var
        TempBlob: Codeunit "Temp Blob";
        FileManagement: Codeunit "File Management";
        BodyText: BigText;
        DataStream: InStream;
        BlobInStream: InStream;
        BodyOutStream: OutStream;
        IsHandled: Boolean;
    begin
        // Note this is intended only to get the body in memory - not from the database.
        Value := '';

        IsHandled := false;
        OnBeforeGetBodyText(Rec, Value, IsHandled);
        if IsHandled then
            exit(Value);

        // If the body doesn't have a value, attempt to import the value from the file path, otherwise exit.
        if not Body.HasValue() and not (("Body File Path" <> '') and Exists("Body File Path")) then
            exit;
        if not Body.HasValue() and ("Body File Path" <> '') and Exists("Body File Path") then begin
            FileManagement.BLOBImportFromServerFile(TempBlob, "Body File Path");
            TempBlob.CreateInStream(BlobInStream, TextEncoding::UTF8);
            Body.CreateOutStream(BodyOutStream);
            CopyStream(BodyOutStream, BlobInStream);
        end;

        if "Plaintext Formatted" then begin
            Body.CreateInStream(DataStream, TextEncoding::UTF8);
            BodyText.Read(DataStream);
            BodyText.GetSubText(Value, 1);
        end else begin
            Body.CreateInStream(DataStream, TextEncoding::UTF8);
            DataStream.Read(Value);
        end;

        exit(Value);
    end;
Another subscriber can be possible but there I cannot set body. Only GETTER are there.
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Email", 'OnEnqueuedInOutbox', '', true, true)]
local procedure OnEnqueuedInOutbox(MessageId: Guid)
begin

end;
Please give any idea. 
  • Asif Shahzad Profile Picture
    384 on at
    RE: EventSubscriber of Table "Email Item" OnBeforeGetBodyText not returning value

    yammer is not accepting .tech domain. My work email is xxxxx@abc.tech

  • Asif Shahzad Profile Picture
    384 on at
    RE: EventSubscriber of Table "Email Item" OnBeforeGetBodyText not returning value

    Thank you Marco.

    I m trying to signup at yammer but didn't get verification email at my gmail. should i give work email?

  • Inge M. Bruvik Profile Picture
    1,029 Moderator on at
    RE: EventSubscriber of Table "Email Item" OnBeforeGetBodyText not returning value

    What version are you on?

    And you are running on-prem if i read your code correctly?

  • Suggested answer
    Marco Mels Profile Picture
    on at
    RE: EventSubscriber of Table "Email Item" OnBeforeGetBodyText not returning value

    Hello,

    We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist. If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    dynamicsuser.net/.../developers

    I will open this up to the community in case they have something to add.

    Thanks.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Now Available: 2025 Release Wave 2

Quick Links

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2,655

#2
Mansi Soni Profile Picture

Mansi Soni 1,574

#3
YUN ZHU Profile Picture

YUN ZHU 1,453 Super User 2025 Season 1

Featured topics

Product updates

Dynamics 365 release plans