Showing posts with label BestPractices. Show all posts
Showing posts with label BestPractices. Show all posts

Monday, October 31, 2022

Code Review

Disclaimer: this is just a short recap of what Martin Dráb explained in his article https://dev.goshoom.net/2012/08/purpose-of-code-reviews/.

Purpose of code reviews

  • Internal quality:
    1. Overall approach – does the code do the right thing by proper means? 
    2. Maintainability/extensibility – are we able to easily extend the solution, fix bugs etc.? 
    3. Testability – are we able to test the code?
    4. Documentation – are we able to understand why the code was made and what it does?
    5. Performance – is the design correct from performance perspective? 
  • Functional testing: Some bugs are much more visible when looking into code
  • Knowledge sharing: Discussions between the developer and the reviewer

Tools

  • BP check 
  • xppbp.exe
  • DevOps code review request

Top 10 issues discovered from Dynamics AX Code Review

https://www.linkedin.com/pulse/top-10-issues-discovered-from-dynamics-ax-code-review-caillet/

Tuesday, March 10, 2020

Data validation by ValidateField and ValidateWrite (old but good)

The most time data are meant to be changed by a user via different kinds of forms or even without it, and sometimes we need to implement additional business logic there.

Say, we want that a discount never be more than 10%, while a user creates lines in a sales order. For such a scenario the best way is to implement ValidateField and check the value for the field of Discount. After that the form does not allow the user to leave the field of discount until its value is less or equal to 10%.


public boolean validateField(FieldId _fieldIdToCheck)
{
    boolean ret;

    ret = super(_fieldIdToCheck);
    switch(_fieldIdToCheck)
    {
        case fieldNum(MySalesLine, Discount):
            if(this.Discount <= 10)
            {
               ret = true;
            }
            else
            {
                ret = checkFailed("Discount cannot be more than 10%");
            }
            break;
    }

    return ret;


But we should remember that ValidateField method is called automatically for a form data source field only.



In other words, if the table record is inserted or updated by code, this logic will be NOT triggered.



[Form]
[DataSource]
     [DataField]
            public boolean validate()
    [Table]
     public boolean validateField(FieldId _fieldIdToCheck)


So, if we need to implement validation logic for the whole record, which is supposed to be triggered every time Insert or Update is called (not for form data sources only), we go with ValidateWrite.






Thanks Mohamed for this brilliant article Microsoft dynamics ax2012 : forms and tables methods call sequences, How To? Watch this presentation! It contains much more very useful information.



Friday, November 15, 2019

Best Practice in real life: SysPolicy form as a bad example

Walk the talk, guys! It can save a life one beautiful day!



Happy weekend to everyone

Wednesday, November 5, 2014

Labels and Best Practices




Guys, please, do not forget that AX is really multilingual system and there are many other languages than English. Happy labelling!