How to assign a value to a field by Event Subscriber on AL/Business Central

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();


    [EventSubscriber(ObjectType::CodeunitCodeunit::"Create Pick", 'OnBeforeWhseActivLineInsert''', false, false)]
    local procedure CreatePickOnBeforeWhseActivLineInsert(var WarehouseActivityLine: Record "Warehouse Activity Line"; WarehouseActivityHeader: Record "Warehouse Activity Header")
        SalesHeader: Record "Sales Header";
        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.";
Thank you!
No Data
  • 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.

No Data