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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Codeunit customization

(0) ShareShare
ReportReport
Posted on by

Hi experts, 

      I have to add a new field as approved (boolean) in the customer table. Then i have to post a sales order for the customer. after entering the items for the sales order, i have to press the post button and select invoice . if i enter the invoice option it has to post an error as not approved customer, since the approved field for the customer is false.

i have created a field in the customer table then , in the codeunit of Sales-post (number: 80) i added the code

  • if customer.Approved <> true then
  •    error(text);

i have delclared all the variables in c/al globals. 

while posting i get the error , even for all the customers whose  approved value is true.

it  would be nice if u help me.

thanks in advance. 

I have the same question (0)
  • Verified answer
    Mohana Yadav Profile Picture
    61,248 Super User 2026 Season 2 on at

    you need to get the customer first.

    If Customer.Get("Sell-to Customer No.") then

     If NOT Customer.Approved then //which means false

       error(text);

  • Community Member Profile Picture
    on at

    Hi mohana,

    Thank you so much. I got that right.

  • Community Member Profile Picture
    on at

    Hi ,

     I have problem when i use the same code outside and call it inside the sales Post(80) codeunit.

    in the line 247 I called customer validation.Run();

    The code inside the customervalidation codeunit is:

    • Documentation()
    • OnRun()
      IF customer.GET(SalesHeader."Sell-to Customer No.") THEN
    • IF NOT customer.Approved THEN
    • ERROR(Text);

    It does not validating the customer Approval field. 

    I have declared all the variables in both the codeunits. 

    Thanks in advance.

  • Verified answer
    Mohana Yadav Profile Picture
    61,248 Super User 2026 Season 2 on at

    you have to pass SalesHeader as a Parameter to Codeunit or a function.

  • Community Member Profile Picture
    on at

    I have done this relation on both the code units and got the answer.

    CODEUNIT.RUN(CODEUNIT::Customervalidation,SalesHeader);

    OnRun(VAR Rec : Record "Sales Header")

    Thank you.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 626 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 425 Super User 2026 Season 2

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 384 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans