I am learning AL/Business Central and wondering how to use event subscriber to add fields on Warehouse Pick and assign values to the fields from Sales Order, like sell to information and ship to information. I use flowfield and there are many fields that a value to be assigned but it uses too much resource to show a page. It takes 15 secs to show the whole page so I was wondering if there’s a different way to make it.
I tried this based on a sample, which can assign a value to a field that is Enum. But it doesn’t work for fields with other formats.
trigger OnRun();
begin
end;
[EventSubscriber(ObjectType::Codeunit, Codeunit::“Create Pick”, ‘OnBeforeWhseActivLineInsert’, ‘’, false, false)]
local procedure CreatePickOnBeforeWhseActivLineInsert(var WarehouseActivityLine: Record “Warehouse Activity Line”; WarehouseActivityHeader: Record “Warehouse Activity Header”)
var
SalesHeader: Record “Sales Header”;
begin
if WarehouseActivityHeader.Type = WarehouseActivityHeader.Type::Pick then
if WarehouseActivityLine.“Source Document” = WarehouseActivityLine.“Source Document”::“Sales Order” then
if SalesHeader.Get(WarehouseActivityLine.“Source Subtype”, WarehouseActivityLine.“Source No.”) then begin
WarehouseActivityHeader.“Sell-To No” := SalesHeader.“Sell-to Customer No.”;
WarehouseActivityHeader.Modify();
end;
end;
Thank you!
Hello, I am just starting with extending BC through code myself, so my answer may not be the best solution, but I see you’ve asked and not had any responses yet. What I do is open the event recorder and run the transaction that I want fields to flow through. I then compare the events that look like they are appropriate to the event in the base system code (extract symbols to get this). As the procedure you define in the event subscriber can only take the same variables being passed as the original event procedure, I look to see if it does (i.e. Sales Header → Warehouse Shipment Header). From there I put the Event Subscriber code in a custom codeunit. When that transaction runs, it calls that event, and triggers your custom code.
https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-subscribing-to-events
Of course, you need to have these custom fields added through extensions to all the appropriate tables. Some transactions use intermediary tables.
Hi Audrey,
What do you mean that it “doesn’t work for fields with other formats”?
The basic rules is that if you are assigning a field to another field, then they most both be of the same type/lengths etc.
When it comes to flowfields, then you cannot assign values directly to flowfields (these are updated based on their underlying tables). And if you need to copy a flowfield to another field, then you need to use calcfields for that the flowfield first.