Skip to main content

Notifications

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;
        }
        
    }
}

  • SammySevens Profile Picture
    130 on at
    RE: Email Editor - Pull Description and get substring to lookup custom field in document

    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;
            }
        }
    }

  • SammySevens Profile Picture
    130 on at
    RE: Email Editor - Pull Description and get substring to lookup custom field in document

    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!

  • YUN ZHU Profile Picture
    81,711 Super User 2025 Season 1 on at
    RE: Email Editor - Pull Description and get substring to lookup custom field in document

    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
    RE: Email Editor - Pull Description and get substring to lookup custom field in document

    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

  • SammySevens Profile Picture
    130 on at
    RE: Email Editor - Pull Description and get substring to lookup custom field in document

    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

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,021 Moderator on at
    RE: Email Editor - Pull Description and get substring to lookup custom field in document

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

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,217 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,978 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans