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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

To display error when a mandatory field is left empty while posting

(0) ShareShare
ReportReport
Posted on by 4,188

Hi All

 I have a field which is a mandatory field hence I've set the 'ShowMandatory' property to True in a page.

If we have only Line Item ,then the field mentioned above which is mandatory should throw error while posting 

but we have multiple line items, and if the field is filled even once then the error shouldn't be thrown on Post

Can someone help me with this?

.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mohana Yadav Profile Picture
    60,999 Super User 2025 Season 2 on at

    what did you write? can you show code?

  • CDsilva Profile Picture
    4,188 on at

    The field is in Purchase Line

    IF PurchaseLine."Gate Entry No."='' THEN

    ERROR('Please enter gate entry number');

    This displays error even if the field gate entry number is filled

    The gate entry field is a lookup.

  • Suggested answer
    Amol Salvi Profile Picture
    18,698 on at

    You should use repeat until loop for making this mandatory as you are checking this on line.

    Repeat

    Purchaseline."Gate Entry No ="" THEN

     ERROR('----')

    UNTIL purchaseline.next=0;

    Hope this will help you

  • Suggested answer
    Mohana Yadav Profile Picture
    60,999 Super User 2025 Season 2 on at

    what type of field is it and where did you write?

  • Suggested answer
    Suresh Kulla Profile Picture
    50,243 Super User 2025 Season 2 on at

    In your case create a new function and in the function add this code pass purchase header as parameter

    PurchLine.RESET;
    PurchLine.SETRANGE("Document Type",PurchHeader."Document Type");
    PurchLine.SETRANGE("Document No.",PurchHeader."No.");
    PurchLine.SETFILTER("Gate Entry No.",'<>%1','');
    IF PurchLine.FINDFIRST THEN
    EXIT
    ELSE BEGIN
    PurchLine.SETRANGE("Gate Entry No.",'');
    IF PurchLine.FINFIRST THEN
    PurchLine.TESTFIELD("Gate Entry No.");
    END;

    If you find any purchase line with entry no. you will not check, but if you did not find then you will check for empty and throw the message.

  • CDsilva Profile Picture
    4,188 on at

    Gate entry number is a text but it is a lookup from another page.

  • Suggested answer
    Suresh Kulla Profile Picture
    50,243 Super User 2025 Season 2 on at

    Is it a field on the purchase line ? doesn't matter what is the source of it. We are checking here if the value exist or not.

  • Suggested answer
    Mohana Yadav Profile Picture
    60,999 Super User 2025 Season 2 on at

    you need to write code in right place. as per your code, it will check for every line (if it is in repeat loop) and throw error if field is empty. it is not checking whether one of lines has value etc.

  • CDsilva Profile Picture
    4,188 on at

    Yes its a field on Purchase Line

  • Suggested answer
    Suresh Kulla Profile Picture
    50,243 Super User 2025 Season 2 on at

    Then try the code i provided and call that function and it should work, If not let us know we can check into it.

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 > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans