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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

How to validate a field in sales line and show error message

(0) ShareShare
ReportReport
Posted on by

on validating quantity in sales line a error message should be pop if the item is blocked on item card 

  modify(Quantity)
        {
            trigger OnAfterValidate()
            var
                ItemS: Record Item;
                SaleslineS: RECORD "Sales Line";
                TEXT2: Label 'This item is blocked %1 ';
            begin
                IF rec.Type = Enum::"Sales Line Type"::Item then
                    if ItemS.Get(REC."No.") then
                        if ItemS.Blocked = true then begin
                            Error(TEXT2, ItemS."No.");
                        end;
            end;
        }
 how to modify this code  
I have the same question (0)
  • Suggested answer
    Nitin Verma Profile Picture
    21,794 Moderator on at

    Hi,

    You can with also Event subscriber of OnValidate for Sales line.

    but see the below code

    tableextension 50102 ModifyQty extends "Sales Line" //37
    {
        fields
        {
            modify(Quantity)
            {
                trigger OnAfterValidate()
                var
                    ItemS: Record Item;
                    TEXT2: Label 'This item is blocked %1 ';
                begin
                    IF Type = Enum::"Sales Line Type"::Item then
                        if ItemS.Get("No.") then
                            if ItemS.Blocked then
                                Error(TEXT2, ItemS."No.");
                end;
            }
        }
    }
  • Community Member Profile Picture
    on at

    Nitin Verma  the above table extended code has no effect is there any solution?

  • Suggested answer
    Nitin Verma Profile Picture
    21,794 Moderator on at

    As soon as you enter the Item No. it automatically validate the Quantity field, is it working my side

    Thanks.

  • Community Member Profile Picture
    on at

    Hi Nitin Verma  thanks for the replies 

    IN CASE: if  I block  a item in item card ex: 0001 and if I tried to add  0001 item in the sales line.  and on validating quantity  a error  should be shown but mentioned code doesnot give any error . am i missing something??

  • Suggested answer
    Nitin Verma Profile Picture
    21,794 Moderator on at

    Then please move your code into Page extension

    pageextension 50104 MyExtension extends "Sales Order Subform"

    {

       layout

       {

           modify(Quantity)

           {

               trigger OnAfterValidate()

               var

                   ItemS: Record Item;

                   TEXT2: Label 'This item is blocked %1 ';

               begin

                   IF rec.Type = Enum::"Sales Line Type"::Item then

                       if ItemS.Get(rec."No.") then

                           if ItemS.Blocked then

                               Error(TEXT2, ItemS."No.");

               end;

           }

           // Add changes to page layout here

       }

    }

  • Community Member Profile Picture
    on at

    Nitin Verma Hi, still it is the same . no changes

  • Suggested answer
    Nitin Verma Profile Picture
    21,794 Moderator on at

    Hi,

    I am getting the error while using the same code, please brief me your steps.

    pastedimage1664153652106v1.png

  • Suggested answer
    YUN ZHU Profile Picture
    99,084 Super User 2026 Season 1 on at

    Hi, I don't think this needs to be customized, the standard system has some controls about the Blocked item.

    More details: How to block items (Block, Sales Blocked, and Purchasing Blocked)

    https://yzhums.com/18968/

    Hope this helps.

    Thanks.

    ZHU

  • Community Member Profile Picture
    on at

    Hi Nitin Verma  I followed exact same steps. I added the code on page extension for sales line and I blocked a item in the item card and tried to add the  same blocked item to the sales line still no any error messages . 

  • Suggested answer
    Amit Baru Profile Picture
    3,037 on at

    Hi,

    Use the below link for reference for doing the above activity.

    https://erpconsultors.com/call-number-field-onvalidate-trigger-via-eventsubscriber/

    Regards

    Amit Sharma

    www.erpconsultors.com

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,005 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,148 Super User 2026 Season 1

#3
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 557 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans