web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Email Editor - Pull Description and get substring to lookup custom field in document

(0) ShareShare
ReportReport
Posted on by 130

Hi All,

We have a requirement that when a purchase order is sent over email to a vendor, that a custom field we generated (requestor) found in the purchase header, should be sent an email letting them know the order was sent. 

Thought it would be straightforward, but I can not access the description field seen below. It is not visible in the intellitext in VS Code - and I don't know how to reference it otherwise (is it hidden somewhere else?).

I would appreciate some help in understanding how to access this field, so that I can include it into the action for the "Send" command

Email page seen below as well, with send email action I am referencing in page extension

pastedimage1684051176683v1.png

pastedimage1684050818801v1.png

pageextension 60031 pExt60031EmailEditor extends "Email Editor"
{
    actions
    {
        modify(Send)
        {
            trigger OnAfterAction()
            var
                emailEditor : Page "Email Editor";
                emailOutbox : Record "Email Outbox";
        
            begin
            end;
        }
        
    }
}

I have the same question (0)
  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,165 Moderator on at

    Have you tried to access the field in the OnAfterGetRecord trigger?

  • SammySevens Profile Picture
    130 on at

    If I understand you correctly, it looks like the same issue.

    The thought was to create a global variable in this page (recordDescription) - and then assign it the value "aftergetrecord"

    From screenshot below, it looks like the field still isn't visible. Why is that the case?

    pastedimage1684080336257v1.png

  • SammySevens Profile Picture
    130 on at

    Ok here is my update.

    I can getrecord and pull in the current page values into a record. This looks great, and I can see the value I want (Description) - but at the table level (BOM Buffer) Access = Internal for that field - so I can not interface with it directly. I chopped up a lot of my code, i used recordref - but since PK is a bigint - i have to format it. That didn't get me far either...i'm still stuck

    My questions now are:

    • How can I access a field that is listed as internal?
    • How do I convert a text field to a recordID field?
      • If it is using recordref - then please review my code below and advise how I can pull out the currentEmailRecordID
        • In the below, you will see that the currentEmailRecordID gets Email Outbox appended to its value....and I can't use it as a key (at least I assume that's why it fails in my get statement)
    • The fields are hidden in blue (for security), but the field in orange below is the field I want, and it is there, and populated....but there is no way to access it! I just want to grab it by index # or somethign....but I can't!

    It's stuff like this about BC's legacy infrastructure that makes it a mess to work with sometimes....

    Thanks for your help

    pastedimage1684102437622v1.png

  • YUN ZHU Profile Picture
    99,492 Super User 2026 Season 1 on at

    Hi, are you looking for the solution below?

    How to change default subject of the email when sending mail in Dynamics 365 Business Central – Customization
    https://yzhums.com/34909/

    Hope this helps.

    Thanks.

    ZHU

  • SammySevens Profile Picture
    130 on at

    Hi Zhu,

    Fantastic suggestion. In the OnAction for the Send button, I just go to this code-unit, and then can access all relevant data and lookups.

    This is the answer I was looking for. But, to be honest....why is the previous approach so difficult? Is it not possible to make internal fields public? Or to use recordref to reference them?

    Appreciate some help to better understand how to use the latter commands when needed.

    Thank you!

  • SammySevens Profile Picture
    130 on at

    Hi Zhu,

    I tried your approach but there is a fundamental issue. I need to call this codeunit/event when the user clicks the send button (OnBeforeAction - Send), code below.

    So I can reference a codeunit that I created (email handler), but I can not call the event subscriber using OnRun trigger - this gives an error : There is no argument given that corresponds to the required formal parameter 'Message' of 'OnSendViaEmailModuleOnAfterCreateMessage(var Codeunit "Email Message", var Record "Email Item" : AL0135)'

    Getting close, appreciate your help, thank you

    codeunit 60010 emailHandler
    {
        [EventSubscriber(ObjectType::Codeunit, Codeunit::"Mail Management", 'OnSendViaEmailModuleOnAfterCreateMessage', '', false, false)]
        
        
        local procedure OnSendViaEmailModuleOnAfterCreateMessage(var Message: Codeunit "Email Message"; var TempEmailItem: Record "Email Item")
        var
            emailSubject: text[100];
            Email: Codeunit Email;
            EmailMessage: Codeunit "Email Message";
            AddBodyMessage: Text;
            BodyMessage: Text;
            userEmail: Text[250];
            userName: Text[250];
            dashSeparator: Text;
            dashSeparatorIndex: Integer;
            PONumber: Code[30];
            purchaseHeader: Record "Purchase Header";
            originalRequestor: Text[100];
        begin
            dashSeparator := '-';
            emailSubject := TempEmailItem.Subject;
            dashSeparatorIndex := StrPos(emailSubject, dashSeparator);
            PONumber := CopyStr(emailSubject, dashSeparatorIndex   2, StrLen(emailSubject));
            /* if purchaseHeader.get(PONumber) then
                originalRequestor := purchaseHeader.origRequestor; */
    
    
        end;
    
        trigger OnRun()
        var
                  
        begin
            OnSendViaEmailModuleOnAfterCreateMessage();
        end;
    }
    

    pageextension 60031 pExt60031EmailEditor extends "Email Editor"
    {
        actions
        {
            modify(Send)
            {
                trigger OnBeforeAction()
                var
                    emailEditor: Page "Email Editor";
                    emailOutbox: Record "Email Outbox";
                    emailOutBoxRecordRef: RecordRef;
                    currentEmailRecordID: RecordId;
                    idFieldRef: FieldRef;
                    bigIntRecordID: Text[100];
                    descriptionField: Text[100];
                    emailCodeUnit: Codeunit emailHandler;
    
                begin
                    emailCodeUnit.Run();
                    /* emailOutBoxRecordRef.Open(Database::"Email Outbox");
                    idFieldRef := emailOutBoxRecordRef.field(1);
                    GetEmailMessage();
                    GetRecord(emailOutbox);
                    bigIntRecordID := FORMAT(emailOutbox.Id);
                    idFieldRef.SetFilter(bigIntRecordID);
                    currentEmailRecordID := emailOutbox.RecordId;
                    emailOutBoxRecordRef.Get(currentEmailRecordID);
                    descriptionField := emailOutBoxRecordRef.Field(6).Value; */
                end;
            }
        }
    }

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

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,933 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,055 Super User 2026 Season 1

#3
Teagen Boll Profile Picture

Teagen Boll 640 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans