Announcements
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
pageextension 60031 pExt60031EmailEditor extends "Email Editor" { actions { modify(Send) { trigger OnAfterAction() var emailEditor : Page "Email Editor"; emailOutbox : Record "Email Outbox"; begin end; } } }
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; } } }
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!
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
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:
It's stuff like this about BC's legacy infrastructure that makes it a mess to work with sometimes....
Thanks for your help
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?
Have you tried to access the field in the OnAfterGetRecord trigger?
André Arnaud de Cal...
294,217
Super User 2025 Season 1
Martin Dráb
232,978
Most Valuable Professional
nmaenpaa
101,158
Moderator