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)

ERROR() or TESTFIELD()

(0) ShareShare
ReportReport
Posted on by 5,596

Hi all,

Just wanted to ask your views on ERROR() and TESTFIELD().

I feel that TESTFIELD() error message is not that user friendly. So I prefer to use ERROR() more than TESTFIELD(). Your views?

*This post is locked for comments

I have the same question (0)
  • Nareshwar Raju Vaneshwar Profile Picture
    5,596 on at
    RE: ERROR() or TESTFIELD()

    Hi,

    My bad. Thank you for correcting me.

  • Verified answer
    RockwithNav Profile Picture
    8,217 Super User 2025 Season 2 on at
    RE: ERROR() or TESTFIELD()

    Hey Nareshwar,

    You cant use TESTFIELD for your custom variables. It's only for Record.FIELD.

    Check out this link.

    https://msdn.microsoft.com/en-us/library/dd301274.aspx

    Hope this helps.

    Thanks

    Blog https://rockwithnav.wordpress.com/

  • Nareshwar Raju Vaneshwar Profile Picture
    5,596 on at
    RE: ERROR() or TESTFIELD()

    Hi,

    As Saurav explained, you can use TESTFIELD() for your custom variables such as, TESTFIELD(MyInt,5).

    Thank you for your response, anyways.

  • Nareshwar Raju Vaneshwar Profile Picture
    5,596 on at
    RE: ERROR() or TESTFIELD()

    Hi Saurav,

    Thank you for valubale input. I always try to implement error messages through TESTFIELDS() rather ERROR() until my the end users complain about the user-friendliness.

    Kudos to you.

  • Nareshwar Raju Vaneshwar Profile Picture
    5,596 on at
    RE: ERROR() or TESTFIELD()

    Hi Natalie,

    Thank you so much for the reply. Will try using FIELDERROR();

  • Verified answer
    RockwithNav Profile Picture
    8,217 Super User 2025 Season 2 on at
    RE: ERROR() or TESTFIELD()

    Hey Nareshwar,

    There's a very clear difference between TESTFIELD  and ERROR, TESTFIELD you can apply only to Record.Fields but Error you can use it anytime anywhere.

    Every time for ERROR you have to give your custom Message whereas TESTFIELD will handle itself.

    If you will ask from Performance and code optimization point of view i will recommend to use TESTFIELD on most of the cases wherever you can.  

    Thanks

    https://rockwithnav.wordpress.com/

  • Verified answer
    Saurav.Dhyani Profile Picture
    14,352 Super User 2025 Season 2 on at
    RE: ERROR() or TESTFIELD()

    Hi,

    It actually depends on situation -

    1. Testfield will give you an error message with the Primary key of the Table.

    2. TestField is not only used to check value is there or not, it also allow you to check a specified value like -

    TestField(MyInt,5) if not 5 you get an error.

    3. With Error you can write your on Error Messages but that depends on how different users will interpret what you write in Error Message. 

    4. When you use error you need to additional line of code to Test the condition, not measure but it adds a load to run that condition.

    To Summarize, Use Error when you actually think it make sense like Sales Line where new users will not know what is line no and all, but what about Microsoft Testfields..

    Lol yes you cannot remove all of those for sure but for setup / Master tables or Table does not have Composite key, i think TestField is the best option  

    Hope i am making sense.

  • Verified answer
    Natalie Karolak - the BC Docs Librarian Profile Picture
    1,955 on at
    RE: ERROR() or TESTFIELD()

    You can use FIELDERROR instead.

    It combines the automatic output of the affected record, with an individual text before it.

    Example (related to TESTFIELD): <Your field> "should be bigger than field X" <in table Y, primary key fields>.

  • Verified answer
    Community Member Profile Picture
    on at
    RE: ERROR() or TESTFIELD()

    Hi,

    This depends on the various programming conditions & related output.

    Testfield would give you common message across NAV, where as Error message text would depends on the programmer, however would be more meaningful to end user.

    If you feel, Error is more helpful, you can certainly go ahead and define your own message.

    Refers following link for more details.

    www.archerpoint.com/.../pierrot-le-fou-testfield-and-error-messages-microsoft-dynamics-nav

    Hope this helps.

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