web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
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 32

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

I have the same question (0)
  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,105 Moderator 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.

  • BC101 Profile Picture
    32 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
    1,105 Moderator 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;
    
    }
    

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,377

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 2,696 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,512 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans