Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

Field Validation Before Saving Sales Header

Posted on by Microsoft Employee

We have a custom field on the Customer Record . . ."Ship-to Code Required". This is true for customers when their Bill-To Address is not valid for shipping. For these customers, we need to ensure that Ship-to Code<>'' prior to saving the Sales Header. 

In Nav 2.5 we had code in the OnActivateForm() event of the Sales Line subform which forced the user to go back and enter a Ship-to code.  How would I do something similar in Nav 2016?

I tried putting this code in the OnValidate trigger of "Ship-to Code" on the Sales Header table however apparently the trigger executes after "Sell-to Customer No." is entered and I can't get past the validation error so this must not be the right place to check.

IF Cust."Ship-to Code Required" THEN 

ERROR(ShiptoCodeReq);

//ShiptoCodeReq is a text constant I defined

Thanks!

Sandra

*This post is locked for comments

  • Suggested answer
    Alexander Ermakov Profile Picture
    Alexander Ermakov 28,094 on at
    RE: Field Validation Before Saving Sales Header

    Also, check Differences Between the Classic Client and RoleTailored Client for OnValidate Trigger: msdn.microsoft.com/.../dd338867.aspx

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Field Validation Before Saving Sales Header

    Problem solved - I put it in Codeunit 80 Sales-Post. That works well enough for me.

    Thanks!

    Sandra

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Field Validation Before Saving Sales Header

    Thanks, I figured out why the OnValidate trigger of "Ship-to Code" didn't work as I expected . . . it's because the OnValidate trigger of "Sell-To Customer No." calls VALIDATE("Ship-to Code",''). This seems very circular to me.

    I also tried the OnNewRecord trigger of the table - apparently it also execute immediately after Sell-To Customer No is entered so I can't move past this field. I want to validate this after the entire header is completed but before sales lines are entered.

    My background is primarily Microsoft Access and in Access, I completely understand the order of events with forms and form controls. This model is very confusing to me. Validate Triggers seem more like events to do other things based on what was just entered rather than actual validation of the new value in the field.

    Any other suggestions? There must be some standard place to put validations that compare values from multiple fields on the same record prior to saving . . . I just can't find it!

  • Suggested answer
    keoma Profile Picture
    keoma 32,675 on at
    RE: Field Validation Before Saving Sales Header

    add your code to trigger sell-to customer no. - onvalidate.

    you could also try the page - onnewrecord trigger or trigger oninsert in table sales header.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans