Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Unanswered

Prevent user from saving the form when no data is modified and validation fails.

Posted on by 133
I have a requirement in AX2012 wherein when user click edit button on a form, but did not modify any data and clicked edit again to cancel, code should perform validation. If the validation fails, user should not be able to click the edit button to cancel (it is like preventing the saving of a form even though no data was modified). 
 
I have placed the validation in the click method of edit button. however I could not prevent the saving of form when the edit button is clicked to cancel, because in the edit button's click method, it cannot return a value. do you have any suggestions?
  • Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    Prevent user from saving the form when no data is modified and validation fails.
    That's not a business requirement either. That may be a way how to achieve a business requirement, but it's impossible to say whether it's the case without knowing the business requirement itself. Note that users and unexperienced consultants often asked for mandatory fields without understanding consequences (e.g. you wouldn't be able to save a customer unless you're able to assign sales tax group, which may be a problem) and without considering alternative designs (such as requiring the information only when needed by a particular business process).
     
    Also note that the design you described before doesn't meet what you've now stated as a requirement. You'd still be able to create customers without sales tax group, you'd be able to save customers without sales tax group and you could have existing customers without sales tax group. All of that violates the requirement that the field must always has a value.
  • Marykate Profile Picture
    Marykate 133 on at
    Prevent user from saving the form when no data is modified and validation fails.
    Hello Martin,
     
    Yes the user requires the field to always have value
  • Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    Prevent user from saving the form when no data is modified and validation fails.
    What you're describing is not a business requirement. You're describing a particular technical design of an unknown business requirement. If you got this from users, it explains why the design is strange - end users usually aren't software architects. Don't let them doing your job. Instead, find out what they need to achieve and then utilize your skills and experience to design a technical solution meeting the requirements.
     
    In this case, users want to ensure that sales tax group is filled in, but the design doesn't ensure it. The first question you should ask them is why they want to do such a validation. This will tell you more about when the validation needs to happen. For example, maybe you'll learn that they require the value filled in always, so you'll need to ensure that. Or maybe you'll find that they need the value at a particular time, e.g. when posting an invoice for the customer, which again isn't covered by the current design and you should do a validation inside that process.
  • Marykate Profile Picture
    Marykate 133 on at
    Prevent user from saving the form when no data is modified and validation fails.
    Hello Martin,
     
    Yes, when leaving the editing mode. 
     
    The business requirement is when leaving the editing mode, always check the sales tax group field has value. If the field is blank, it should prompt an error and not allow user to leave the editing mode. If the field has value, user will be able to leave the editing mode. 
     
    (please note that I only used the sales tax group field as a sample)
  • Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    Prevent user from saving the form when no data is modified and validation fails.
    Aha, so you mean doing it when leaving the editing mode.
     
    What is the underlying business requirement? Your technical design looks strange to me, but maybe I'll understand when you explain the requirements, or I'll be able to suggest a better solution.
  • Marykate Profile Picture
    Marykate 133 on at
    Prevent user from saving the form when no data is modified and validation fails.
    Hello Martin,
     
    Yes your understanding is correct.
     
    Sample is: In the customer master form, there is an edit button in the action pane.
     
    When the edit button is clicked once (to edit), it becomes like this. 
     
    If the user doesn't modify any data in the form, and clicks the edit button, I want to run a validation to check if a field is empty. If yes, the edit button should remain as below:
     
    And the edit button should not be allowed to be like below if the validation fails.
     
     
    Do you think it is possible? 
    What i have done is to override the clicked method in the edit button, and put the validation there. However even when the validation failed, the edit button is still able to become like this:
  • Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    Prevent user from saving the form when no data is modified and validation fails.
    You said you "could not prevent the saving of form", but this doesn't seem to make sense. You said that nothing was changed and no saving happens, therefore there is no saving to prevent. It seems to me that you want to run a validation even when nothing is being saved, not to "prevent the saving". Do I understand it correctly?
     
    Can your form show multiple records? If so, do you want to always validate all of them, or how are you going to decide which should be validated and which should be ignored?
     
    Also, it's not clear to me what you mean by "clicked edit again to cancel". Can you elaborate it, please? Maybe you should tell us a bit more about the process and the form.
     
    This thread has been moved from Dynamics 365 general forum to Dynamics AX forum.
  • Marykate Profile Picture
    Marykate 133 on at
    Prevent user from saving the form when no data is modified and validation fails.
    Hello Martin,
     
    I am using MS dynamics ax 2012.
  • Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    Prevent user from saving the form when no data is modified and validation fails.
    Which D365 app are you using? This forum is about D365 in general, while your question seems to be about a particular product (such as Finance and Operations or Business Central).

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

Product updates

Dynamics 365 release plans