2018 m. liepos 10 d., antradienis

14 Tips to Become a Better Questioner in Dynamics Community Forum

Hello AX World,

Our community is growing and we all have questions to ask. Dynamics Community Forum is a great place to ask a question or two. I have been reading this forum for quite some time and I have noticed a trend of questions getting low in quality. So here, I am giving some tips how to become better at asking a question.

1. Have you done your work? Make sure you have tried everything you know yourself. It´s so unprofessional when someone is lazy ant tries to find quick answer without himself putting the work in it. e.g. debugging your code. You won´t become a professional this way.

2. Be clear. Try to describe your problem as clear as possible. Do not get into unnecessary details, but also give as much context as possible to understand the problem.

3. Get to the point. Make sure you asked a question. I have seen some examples with no question at all.

4. Do not overload the question. Pasting a log into a question is probably not a good idea. Imagine yourself scrolling down all this log just to see if someone answered. If you have a large chunk of the log, just upload it somewhere else and link it in the question.

5. Keep the code nice and sound. If the question includes a code sample, try to make it nice and clear so we don't have to hurt our eyes reading it. Best practices are made on purpose.

6. Your English is good. Do not mind if your English is imperfect. It´s a first or second foreign language for most of us. If we don’t get your questions we will tell you. There are native English speakers who don’t know a second language. You know it and you rock!

7. Stick to original question. Try not to deviate from your original question. If you have another question, it is better to create one more post.

8. Nobody will do a dirty job for you. Do not expect we are going to do a dirty job for you. We´re not going to debug for you. We are not going to have a call to solve the problem for you. If you need that kind of help, you have to contact professional services and probably pay for it.

9. Follow up. Don’t just leave your question. If someone asked for more details try to answer and give those details. I’ve seen too many questions left alone in the dark.

10. Share your resolution. If you’ve managed to solve your issue by yourself, why don't you just share it with others and close the question.

11. Verify the answer. Show others that the question have been solved and verify the right answer. This way community will know that this question is solved. Everybody wants to get little reward for solving others´ questions.

12. We are all equal. Don´t call others titles like sir. or whatever fancy title, even if you are used to it in your country. It’s the Internet; we are all equal, just some have less experience some have more.

13. Update your profile. So everybody can call you by the name and not by the nick name.  It is so weird when someone answers 'Hi Bot' or whatever crazy nickname someone have.

14. Be nice and do not get personal. It´s not a place for that. We all are humans and sometimes we can get emotional but try to be professional.

I hope these tips will help to improve the quality of questions asked in Dynamics Community Forum.
If you liked this or any other post of mine don´t forget to subscribe to my blog posts, follow me on twitter @evaldasland or add me on LinkedIn.

Be aware and take care!

2018 m. liepos 3 d., antradienis

Icons on a Grid

Hello AX World,

In this short blog post I will show you how easy is to add an icon on a grid in Microsoft Dynamics 365 for Finance and Operations.

There are various different ways to add images on the form, but this one is my favorite.

The concept used here is called symbol font. It's a list of predefined icons that you can lookup by text ID.

You can lookup icons available here.

You only need to do two things:
    1. Create a display method.

    2. Create an Image type control that uses the display method.

    That's it! Now you have icons on a grid.

    Be aware and take care!

    2018 m. birželio 28 d., ketvirtadienis

    DYN365FO Form Drill Through Opening Wrong Form

    Hello AX World,

    Recently I have run into an issue. I am in the list page and trying to click through some ID to get to the form I expect and I get a completely different form opened. Strange…

    Hey, if you don't have time to reading all this story, the bottom line is that the order of the relations of the table might be important for your form drill through. It may open a different form.

    So I tried  several different options.

    First, I immediately checked FormRef property on the table. It was missing, so I set it right.
    Building. Refreshing. Trying… no luck.

    Then, I checked relations on the EDT of the primary key. Relations were not present, table reference either. So I set table reference as I could not set relations. It´s an obsolete thing since AX 2012.
    Building. Refreshing. Trying… no luck again.

    Then I started to look into code of the list page and it´s interaction class and asked about this problem on my twitter account and dynamics community. Got some hints but still… no luck.

    Why I am getting a completely different form? FormRef was fine, all the references in the menu items and EDT were fine too. What´s wrong then?

    And one though hit my head, what about table relations. Does the table have a relations to itself?
    No, it does not! Quickly creating a relation to itself.
    Building. Refreshing. Trying… no luck again.

    Why? Quickly glancing at the relations list and noticing something interesting. There is one more relation where this single ID field is involved and it relates to another table which FormRef seems to be opening.
    Could this be a problem? But why could this relation be used instead of the relation to itself that I just created? Is the order of the relations important?

    Trying that out. Selecting my relation to itself and clicking Alt+Up few times until it gets first in the order.
    Building. Refreshing. Trying. Bingo!!!
    Turns out the order of the relations is IMPORTANT.
    Who would have though that?

    I hope this helps you and saves some precious time of yours.

    Be aware and take care!

    2018 m. gegužės 3 d., ketvirtadienis

    Dynamics AX Logical Expression Optimization

    Hello AX World,

    Recently I was reading about Chain of Command (CoC) and found one important statement that I was aware of but have never found in any of the documentation.

    "Because logical expressions are optimized, calls to next can't occur in logical expressions. At runtime, the execution of the complete expression isn't guaranteed."
    From <https://docs.microsoft.com/en-us/dynamics365/unified-operations/dev-itpro/extensibility/method-wrapping-coc>

    The important part is about that logical expressions are optimized in Dynamics AX. Here I will try to explain how it is optimized and why it is important to know it.

    It is important to know that as it may help you:
    1. to avoid getting in situations where your code is not executed and it should be.
    2. to improve performance by not necessarily executing code that is time consuming;

    Have a look at this and consider if all expressions are tested?

    The answer is it depends on expression. 
    My experience shows that it starts testing operands from left to right.

    Have a look at this code sample.

    Code sample 1

    Running this would result in  expression1 tested only. It returns true for the first operand so for optimization purposes it skips all the others.

    Code sample 2

    Lets change so expression1 returns false.

    Now it checked expression1 and expression2 and skipped the 3rd.

    If I make expression2 return false too it will force to test expression3.

    Lets have another example with different operators in expression.

    Code sample 3

    The result is expression1 and expression3 tested and expression2 is skipped for optimization.

    Or have a look at the next example.

    Code sample 4
    I have changed expression1 and expression2 to return false.

    The result is expression3 skipped as the first AND operand returned false, so there is no meaning to test expression3.

    You can play around with similar code but the message is quite clear: be aware of this optimization.
    It applies to all versions of Dynamics AX. 

    There are many examples of this in standard application and I used to develop having this optimization in mind as I like fewer code for better readability.

    Sometimes it might skip some code that you would not like to skip or it might help to improve performance. Though there are more clear ways to improve performance.

    Few examples from standard code...



    Be aware and take care!

    2015 m. birželio 17 d., trečiadienis

    AX Source Code Quality: Top 10 X++ Coding Commandments 1.1

    Hello AX Word,

    This time I came up with an idea to list top 10 coding guidelines. We would all write a better code if we followed them.

          0. You shall check your code for best practices.
    1. You shall use a proper case for X++ code: start variables, functions, keywords with a lower letter; start application elements with a capital letter.
    2. You shall indent you code appropriately.
    3. You shall add curly brackets around every if, else, loop, switch (except case) and while select statement.
    4. You shall use meaningful names of variables, functions and application elements.
    5. You shall add a single spaces around operators, after commas, if, switch, case, loop keywords.
    6. You shall not use spaces before function parentheses, case's semi-column, ++ and -- operator, after ! (exclamation mark).
    7. You shall avoid using hard-coded values, especially for interface texts.
    8. You shall breakdown long statements.
    9. You shall use column style alignment.
    10. You shall cleanup unused code.
    The list is subject to change if I get a more valuable best practice than one above. So this was named 1.0 :)

    P.S. I wonder if there is beautifier tool somewhere in the market?

    Be aware and take care!

    2015 m. birželio 8 d., pirmadienis

    AX Source Code Quality: Complex Select Statement Layout

    Hello AX World,

    One of the key factors that make your code look ugly is layout. There is a very good guidance for that on MSDN site. Everything looks clear when you read it. But when it comes to coding you start wondering how should I make this select statement adhere to best practices? How should I align this complex where clause?

    My basic rules are:

    1. Follow MSDN guidelines for select statement.
    2. Use proper indentation.
    3. Keep field list compact.
    4. Make where clause look nice.

    Follow MSDN guidelines for select statement.

    It also includes while select, update_recordset and delete_recordset.

    There are some rules which I am not big fan of.
    First is that boolean operators should be placed at the beginning of the line. Well, even standard code does not always adhere to that rule.

    Does this look nice?
    When I try to write boolean operators in the beginning of a line I often consider which style should I use A or B?


    When I write boolean operators at the end it's almost no question.

    Second is alignment of from/order by/group by/index keywords. I prefer indenting them twice for a better readability. But this can be questioned.

    Use proper indentation

    I follow these guidelines:
    • Indent once where and setting keywords;
    • Do not indent joins. Put them at the same level as first statement (see very last example);
    • Indent group by/order by/index and from (if its moved to a new line) at least once.
      I prefer indenting then twice.
    Keep field list compact

    Follow the rule: if a field list contains more than 5 fields or it exceeds 100 chars, break it down and use column alignment. Use one column then breaking down.
    This rule applies for field list, order by, group by and setting field list.

    Make where clause look nice

    This one is not an easy task. Especially, then it is a very complex where clause with lots of ANDs an ORs.

    Follow these rules:
    • One comparison per line except if it's very short.
    • Then using clauses indent expressions inside by one space except the first one. Keep the first expression in the same line as opening clause "(". Closing clause ")" should be placed at the end of the last expression inside the clause.
    • Rearrange expressions to make it more readable. Try to keep the similar expression close to each other. 
    • Then using NOT operator "!" treat is as part of expression. Don't use special alignment.
    • Then writing AND and OR at the end make them leveled as clauses so the structure can be easily recognized.
    Consider this example. Does this look nice?
    It's code from standard class BatchRun method serverProcessFinishedJobs

    Does this look more readable?

    Or maybe this?

    You are more than welcome to share your experiences and best practices. Please give a proper reason why you are doing it one or another way.

    Be aware and take care!

    2015 m. gegužės 15 d., penktadienis

    AX Source Code Quality: What is a Bad Source Code?

    Hello AX World,

    During my short career I have had a chance to see lots (50+) of different AX implementations and solutions from various countries. I have seen both good and bad code. Unfortunately, in most of the cases it was a bad code. And its a problem, because a person who is reading a bad source code can get frustrated quickly.

    But what is a bad code? Why it's bad? How to make it better? To answer these questions and to help you to write a better code I am going to start a series of blog post regarding AX source code quality. I am also open for discussions as there are many arguable topics (e.g. code commenting).

    I will start my first post with an example to consider:

    Keep in mind, this is an overridden method in a class extending RunBase class (from RunBase framework. Ignore the fact that RunBase is an obsolete framework in AX 2012.

    How many bad practices can you notice? Before reading it further try to test yourself.
    So, how many issues you have noticed? 1, 2, 3,... more?

    Let's try with some bad practice basics.

    1. Application elements should be started with a capital letter to easily distinguish them among variables.
    2. Brackets missing around if statement even if its a single line for a better readability.
    3. There should be a single space between addition operators.
    4. There should be a single space after a separator.
    5. Redundant empty line.

    Got the idea? Now lets move on with more sophisticated issues.

    6.There should be a single label and preferably strfmt function be used instead  of two labels and a number of adding operators.

    7. Instead of calling infolog.add method, error method could be called as it contains the same code and requires only one parameter, the text.

    8. Validation logic should be moved to a validate method instead. The method getFromDialog is used to parse values from the dialog after it has been closed by clicking OK. This method has the code which calls validate method afterwards.
    9. Validation code could be optimized. Well, this can be arguable.
    So I have found 9 problems. Is that a lot for 20 lines of code? Maybe an eagle-eye professional could add even more. All thoughts are welcome.

    So to finalize the first post I strongly believe that the code should look like this:

    If you can see any issues with my suggested code, feel free to comment.

    Be aware and take care!