Skip to main content

Notifications

Announcements

No record found.

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 Microsoft Employee

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  
  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,081 Super User 2024 Season 1 on at
    RE: How to validate a field in sales line and show error message

    Hi,

    As Amit mentioned please go with Event Subscriber in that case, if its not working, but it strange, how its possible, its working in my system with same code, can you please check if you anyother code related this.

  • Suggested answer
    Amit Baru Profile Picture
    Amit Baru 3,027 on at
    RE: How to validate a field in sales line and show error message

    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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to validate a field in sales line and show error message

    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
    YUN ZHU Profile Picture
    YUN ZHU 75,848 Super User 2024 Season 2 on at
    RE: How to validate a field in sales line and show error message

    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

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,081 Super User 2024 Season 1 on at
    RE: How to validate a field in sales line and show error message

    Hi,

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

    pastedimage1664153652106v1.png

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to validate a field in sales line and show error message

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

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,081 Super User 2024 Season 1 on at
    RE: How to validate a field in sales line and show error message

    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
    Community Member Microsoft Employee on at
    RE: How to validate a field in sales line and show error message

    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
    Nitin Verma 21,081 Super User 2024 Season 1 on at
    RE: How to validate a field in sales line and show error message

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

    Thanks.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to validate a field in sales line and show error message

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

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans