
I have been a software developer, working mainly with Visual FoxPro and C# for over 20 years.
Recently, I was asked by a customer if I could develop a simple solution for Business Central. I have since followed all the relevant courses on AL programming for Business Central within Microsoft Learning and so I am now trying to write the solution.
The customer simply wants the description entered on each Sales Order line to be copied to the corresponding Purchase Order line. The standard system populates the Purchase Order description from the Vendor product record.
Using Shift+Alt+E in Visual Studio Code, I found what appeared to be an ideal Event, and created the code below:
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Purch. Doc. From Sales Doc.", 'OnCopySalesLinesToPurchaseLinesOnBeforeInsert', '', true, true)]
local procedure OnCopySalesLinesToPurchaseLinesOnBeforeInsert(var PurchaseLine: Record "Purchase Line"; SalesLine: Record "Sales Line");
begin
PurchaseLine.Description := SalesLine.Description;
end;
I deployed this to my sandbox to test, but it did not work. I added a Message() and this did not appear.
I used the Event Recorder to check whether the event was firing after selecting Actions - Functions - Create Purchase Document - Create Purchase Orders from the Sales Order. The "Purch. Doc. from Sales Doc." event/codeunit did not appear.
I tried subscribing to several other events. These did fire, and I was able to display test messages to confirm that my code was deploying correctly. However, I could not find another event where both the Sales Line and Purchase Line were both available. Also, even if I tried to update the Purchase Line description, this did not change what appeared on the created Purchase Order.
As this is my first Business Central project, I really don't know whether I am doing something wrong, or if this is a bug with Business Central, or something else!
The Business Central version is shown as below in Troubleshooting:
Version: GB Business Central 19.2 (Platform 19.0.32956.35068 + Application 19.2.32968.33612)
I would greatly appreciate any help at all. Thanks in advance.
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.
dynamicsuser.net/.../developers
I will open this up to the community in case they have something to add.
Thanks.