Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Answered

Correct coding in Visual studio code for boolean in Business Central

(0) ShareShare
ReportReport
Posted on by 20

I am attempting to create a selectable column on the sales invoice page using a boolean in visual studio code, but having trouble. Does anyone have any suggestions on the correct coding to make this possible? I also created this field on the customer card and will like for it to be linked to the column in the sales invoice. How would I go about that? Below are some pictures that can show my progress so far. Thank you.

Boolean-pt.-1.pngBoolean-pt.-2.pngBoolean-pt-3.png

  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,748 Super User 2024 Season 1 on at
    RE: Correct coding in Visual studio code for boolean in Business Central

    First of all i think you probably want to extend the Sales Header table with your new field and not only the sales Invoice Header.

    The sales Invoice Header is the posted document. And you probably want to set you field on the sales header and then let it flow to the sales invoice header from there.

    Then you need to add a codunit as i show here. The codeunit subscribe to the event and do the needed changes to the salesheader.

    Then make sure your new field have the same field number in both the sales header table and the sales invoice table.  If that is the case the standard posting function will make sure the value is transferred from the sales header to the sales invoice.

    codeunit 90012 EvenSubscriberSalesHeader
    {
        [EventSubscriber(ObjectType::Table, Database::"Sales Header", 'OnValidateSellToCustomerNoAfterInit', '', false, false)]
        local procedure OnValidateSellToCustomerNoAfterInit(var SalesHeader: Record "Sales Header"; xSalesHeader: Record "Sales Header");
        Var
            Customer: Record Customer;
        begin
    
            Customer.get(SalesHeader."Bill-to Customer No.");
            SalesHeader."Customer Invoice Required" := Customer."Customer Invoice Required"
            SalesHeader.Modify(True);
    
        end;
    
    }
    

  • BC101 Profile Picture
    BC101 20 on at
    RE: Correct coding in Visual studio code for boolean in Business Central

    Would I include this in the field bracket under caption and editable? Or begin after line 16? Could you also include the correct brackets it seems that I am getting a lot of errors.

  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,748 Super User 2024 Season 1 on at
    RE: Correct coding in Visual studio code for boolean in Business Central

    You should subscribe to this event in the sales header table:

       [IntegrationEvent(false, false)]

       local procedure OnValidateSellToCustomerNoAfterInit(var SalesHeader: Record "Sales Header"; xSalesHeader: Record "Sales Header")

       begin

       end;

    And there you can populate the salesheader with the value from the boolean field from the customer.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,391 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans