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

How to make sure fields are filled in

(0) ShareShare
ReportReport
Posted on by

I am trying to put something in so that on somecards the user cannot leave the page without completing certain fields....I have done it by using    IF "field name" = '' THEN ERROR ...     under OnModify, which kind of works but it means if a user has not filled in a required field out they lose all the work they entered on that page to clear the error.  Is there another error function (or anything similar) that insist on the required fields for us but doesn't make you lose all your changes?

Thanks for anyone's help!

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Tharanga Chandrasekara Profile Picture
    23,118 on at
    RE: How to make sure fields are filled in

    Use TESTFIELD function.

    Refer below link :

    msdn.microsoft.com/.../dd301274.aspx

  • Suggested answer
    Saurabh Shah Profile Picture
    4,560 on at
    RE: How to make sure fields are filled in

    Hi,

    As you need that when user close the page system should check the defined fields for some value if those are empty then system should give the error.

    Yes, You should use the TESTFIELD() function as suggested by Tharanga Chandrasekara but the event to check should be case to case like if it on master cards like item card, vendor card then you can write testfield on Closepage () and for transaction like Sales order or purchase order, On release event you can check those fields.

    Regards,

    Saurabh Shah

  • Tharanga Chandrasekara Profile Picture
    23,118 on at
    RE: How to make sure fields are filled in

    Completely agree with Saurabh Shah. For each scenario you should use different triggers.

  • Suggested answer
    Mohana Yadav Profile Picture
    60,967 Super User 2025 Season 2 on at
    RE: How to make sure fields are filled in

    There  are some posts and blogs already discussed about this.

    please search

    stackoverflow.com/.../how-do-i-require-a-field-to-be-mandatory-on-a-nav-page

    www.clientsfirst-us.com/.../dynamics-nav-navision-implementing-mandetory-fields

    dynamicsblog.wordpress.com/.../why-are-mandatory-fields-baaad

  • Community Member Profile Picture
    on at
    RE: How to make sure fields are filled in

    Thanks for everyone's help. 2 things I'm still struggling with?:

    - I can get an error to happen on a 'code' field but not an 'option' field - is there a particular way of putting it for option fields?

    - When the error comes up, I would like to be able to fill in the field and clear the error without losing other changes I have made. When I try to do this is says 'the key fields are not valid' as a separate error - then I have to lose all the changes just because I missed one small (but important!) field.

    Is there solutions for these?

  • Mohana Yadav Profile Picture
    60,967 Super User 2025 Season 2 on at
    RE: How to make sure fields are filled in

    Can you show us the code what you have written?

  • Community Member Profile Picture
    on at
    RE: How to make sure fields are filled in

    Certainly -

    This is on the contact table, under OnModify(). 'Customer Class Code' is a custom field of type 'code' which looks at the dimension table for its values.

    OnModify(xRec);

    Cont."Customer Class Code" := '';

    Cont.TESTFIELD("Customer Class Code");

    This creates an error at the right time (when trying to move away from the record) - but when I try to complete the Customer Class Code field as required I get a second error alongside 'This field cannot be validated since the key fields are not valid'.

    Then also when I do the same code but on an 'option' type field instead it won't even save the table in the dev env..

    thank you

  • Community Member Profile Picture
    on at
    RE: How to make sure fields are filled in

    Did my code provided help to clear the questions?

    Any further help is much appreciated.

  • Verified answer
    Tharanga Chandrasekara Profile Picture
    23,118 on at
    RE: How to make sure fields are filled in

    So you want this error to pop up when the user did not enter any input to your custom field in the contact card?

    In table level there are very important triggers you need to understand.

    1. OnInsert - This trigger execute when a user fill in all the primary key values. That means as soon as user completes entering data to last primary key, this trigger get executed.  As a example if a table has composite primary key ( more than 01 key as primary key) , this trigger only get executed when the last primary key field is fill in. 

    2. OnModify - This will  get executed when a user move away from the record after doing any modification to a field in the table.  

    03. OnRename - If the primary key is changed this trigger will get executed.

    So in your case when you create the contact, and when the user enter the contact No. it will execute the OnInsert trigger and without any error code get executed and record is inserted to the table. ( only the primary key values)

    Then you will enter all the data to the other fields in the contact card and did not enter data to the field that you have written TESTFIELD  in the OnModify trigger and if you tried to move to next record or try to close the page it will throw a error and if you simply ignore it, what will happen is you will lose your entered data.

    Reason : Because when u try to move away from the record after modifying, system will call OnModify trigger. Then in that trigger, error get thrown and system will not complete the execution and will rollback all the data of the particulate modification. 

    So I think it is better to move your code to OnClosePage trigger. 

    TESTFIELD("Customer Class Code");


    
    
  • Chanky Dayalani Profile Picture
    5 on at
    RE: How to make sure fields are filled in

    Hi Tharanga,

    Here by writing Code on OnClosePage trigger, the purpose of this requirement is not resolved. As, the page gets closed simply by giving error. Rather, as per the need, it should remain on the same Page so as to allow user to enter correct data, right @THREEEA?

    Also, user can simply jump to next record and skip this control of error validation and leave behind erroneous data.

    I don't think this solution should work. Any idea about more better solution please?

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

#1
Saurav.Dhyani Profile Picture

Saurav.Dhyani 2 Super User 2025 Season 2

#2
RK-25090803-0 Profile Picture

RK-25090803-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans