Microsoft Dynamics AX Editor Scripts

Microsoft Dynamics AX Editor Scripts

March Blog Series: Connectivity

Insights from: Bill Concepcion (Fullscope Technical Consultant)​

Microsoft Dynamics AX developers know firsthand there are many key statement frameworks that are written repeatedly. For example, when a developer needs an "if" statement, the following sequence may occur:

  • Type "if ()" and press <Enter>
  • Type "{" and press <Enter>
  • Type "}" and press <Enter>
  • Move the cursor in between the open and close parentheses
  • Write the expression to be evaluated.
  • Move down to the end of the opening curly brace and press <Enter>
  • Write the statements for when the expression is evaluated as true

Other than the expression and the statements within the "if" block, the "if" statement is always the same—similar to the "else", "for", "while", "while/do" and "switch" statements.

There are also common method templates such as "parm" methods and "construct" methods. The templates in these are always the same, and any developer can write one easily. In fact, if a developer makes a typo while typing the template, there are mixed feelings of mild irritation and mild excitement: mild irritation because it will now take the developer longer to do a menial task, but there is mild excitement because it's something different from the same repetitive task.

What if common templates were written for developers? Dynamics AX has these scripts.

A developer might think, 'Oh, I know about those scripts. Not impressed.' If a developer is thinking of applying one of those scripts through context menus, then there would be reason to be unimpressed. It's faster to type the statement explicitly to go through the context menus.

What if there were a faster way for a developer to write a statement template? There is a way! Whenever an "if" statement is needed, type "if" and then <Tab>. The entire "if" statement is written out for the developer, and the cursor is placed between the two parentheses after the "if"—the expression is ready for evaluation. Neat!

To do an "else" statement: Create a new line after the } and type "else" and then press <Tab>. Voila! An "else" template is written.

The <Tab> triggers the appropriate script execution to build the template. This is much faster than having to go through the context menus. This works for all of the flow keywords ("do", "else", "for", "if", "ifElse" [the "E" must be capitalized], "switch", "try" and "while"). Simply type the keyword and press <Tab>, and the framework is written for the developer with the cursor placed in the correct spot.

It also works for the following methods: "construct", "main" and "parm". Create a class (these won't work in jobs or tables), and then create a method. Press <Ctrl-A> so that the entire method is highlighted. Type "construct" and press <Tab>. The construct method is then created for the developer. If the class name was not changed before creating the construct method, then the script writes the construct method to return Class1. "main" works similarly, but "parm" works a little differently. The triggering of the script is still the same: Create a new method, press <Ctrl-A>, type "parm", and press <Tab>. This time the developer will be presented with a form.

The Type field has a drop down of different types, but the chances are good that the developer might need to create a "parm" method for a custom object. In either case, just type the data type in the Type field. In the Variable name field, type the name of the variable defined within the class that is being used as a parameter. For example, if the following parameter is defined in the class declaration as:

The Type field should contain "CustTable", and the Variable name field should contain "myCustTable". Click on the OK button and the developer will get the "parm" method.

It doesn't end there. Create a script for the "edit" method from a table by pressing <Ctrl-A>, type "edit" and press <Tab>. Just like with the "parm" method script, the developer is presented with a form.

If the extended data type name is "SalesId", the table name is "SalesTable" and the variable name is "salesId", then this would be the resulting code:

The "editWithClass" is similar to the "edit" method script, but it uses a class to process the field being set. For example, (building on top of the example above with the "edit" method script) if "SalesLineType" is the class being used, and it had a method called "abc" (with everything else remaining the same) the "editWithClass" method script would produce the following template:

Microsoft Dynamics AX includes built-in scripts that can help a developer create code faster. The hard part is remembering to trigger them. Enjoy!

Contact us today for more information on what Fullscope and Microsoft Dynamics AX ERP solutions can do for your manufacturing business.

AX Technical Tip, Microsoft Dynamics AX ERP, AX Implementation, ERP t, Microsoft Dynamics ERP