Thursday 24 May 2018

Access modifiers in X++ Language (AX2012 & D365)


There are several access modifiers that can be applied to method declarations. Some of the modifiers can be combined (for example, final static). Some modifiers can only be used methods, while others can be used on classes or methods.

The following list describes the method modifier keywords of the X++ language.

Abstract: The method is declared but not implemented in a parent class. The method must be overridden in sub classes. If you try to create an object from a subclass where one or more of the abstract methods belonging to the parent class have not been overridden, you will get a compiler error.

Note: Classes can also be abstract. Sometimes a class represents an abstract concept, but it should not be instantiated: Only sub classes should be instantiated. Such base classes can be declared abstract. Consider the case where the programmer wants to model the concept of an account. Accounts are abstract—only derived classes (ledger accounts and so on) exist in the real world. This would be a clear case for declaring the Account class abstract.

Final: Indicates that the method cannot be overridden in any class that derives from its class.

Public: Methods that are declared as public are accessible anywhere the class is accessible and can be overridden by sub classes. Methods that have no access modifier are implicitly public.

Protected: Methods that are declared as protected can only be called from methods in the class and in sub classes that extend the class where the method is declared.

Private: Methods that are declared as private can be called only from methods in the class where the private method is declared.

Client: Establishes the location where the method is to be executed (on the client). Can only be used on static methods. If the method is not static, specify the location by using the class property RunOn.

Server: Establishes the location where the method is to be executed (on the server). Can only be used on static methods. If the method is not static, you need to specify the location using the class property RunOn.

Display: Indicates that the method's return value is to be displayed on a form or a report. The value cannot be altered in the form or report. The return value is typically a calculated value, for example, a sum.

Edit: Indicates that the method's return type is to be used to provide information for a field that is used in a form. The value in the field can be edited.

Static: Specifies that the method is a class method and does not operate on an object. Static methods cannot refer to instance variables and are invoked by using the class name rather than on an instance of the class (MyClass::aStaticMethod()).

Wednesday 23 May 2018

Basic Outputs in D365

In Dynamics 365 we can show outputs in three different ways.

1- By using box class
The box output will create a popup box displaying text to the user.

2- By using info class
Info log will display on the top of the window as ribbons. The type of info message (info, warning, or error) will define the color and symbol used to display the information.









Also by using setPrefix, you can create an info message with a “Message details” link.  The link will show the info statements created after the call to “setPrefix”.  You need to include more than one info statement for the “Message details” to appear.










3- By using dialogButton class
A dialogbutton set to a box will create a popup box asking for input from the user. The results of which button was selected will be set to the dialogButton variable.






Tuesday 22 May 2018

Macros & Const in AX7 / D365

Macros can still be created in Dynamics 365 for Finance and Operations to store a value that will not be modified.  They are created in either a macro file or by using the pound define keyword.  So we can see that here with our either hash tag or pound define.  

However, there is a new modifier to create constant variables.  By placing the keyword const before a variable, it will create the value that cannot be modified.

Const allows you to define members on a class and variables in a method that can only be initialized during the declaration. Constant value must be known at compile time. Compiler will replace references to these constants with the literal value.

Const also replaces most use cases of macros.

Example code:













Key Benefits:
IntelliSense in the editor.
- Support for "Go to definition" in the editor.
- Full control of the type for the constant.
- Faster compilation – macros are notorious hard for the compiler to handle.
- None of the macro idiosyncrasies – like the ability to redefine/override.

Reference link: X++ in AX7: Const keyword

Tuesday 15 May 2018

Tips & Tricks for Debugging in Visual Studio for D365

In this blog, I have covered some tips and tricks supported for D365 in Visual studio.

Tip # 1 - Pin data tips
While debugging code we have frequently hover over data tips in order to see the values contains in variables. In VS we can pin the data tip for the variable to give our-self quick access. To pin the data tip, click the pin icon while hovering over it. You can pin multiple variables.

First way to pin is to select your variable and right-click it as shown in image.


Second way to pin is to hover your variable click pin icon.













Tip # 2 - Conditional Break points
If it is difficult or time-consuming to recreate a particular state in your app, consider whether the use of a conditional breakpoints can help. Right-click a break-point icon (the red ball) and choose Conditions. In the Break-point Settings window, type an expression.















Tip # 3 - Track an out-of-scope object
We can view variables values using debugger window. However, when a variable goes out of scope in the Watch window, you may notice that it is grayed out. In VS we can track those variable by creating an Object ID for it in the Watch window.

To Create an object Id:
- Set a break-point near a variable that you want to track.
- Stop your break-point at your variable.
- Find variable in the Locals window (Debug > Windows > Locals), right-click the variable, and select Make Object ID.
- Right-click the object ID variable and choose Add Watch.

















Tip # 4 - View return values for functions
In order to view return values for your functions, look at the functions that appear in the Autos window to see the return value for a function, make sure that the function you are interested in has already executed.













Tip # 5 - Format your string in a visualizer
When working with strings, it can be helpful to view the entire formatted string. To view a plain text, XML, HTML, or JSON string, click the magnifying glass icon Visualizer Icon while hovering over a variable containing a string value.
















Tip # 6 - Manage breakpoints
In VS when we set-up some breakpoints and now we need to switch one-off for as it’s getting hit too much but we will need it again for debugging. If we remove the break-point we’ll have to come back and find it again. So instead of removing the break-point we can use Break-point window. This window will show all breakpoints you have set but crucially lets you disable them without un-setting them by simply removing the check-mark. Check it again to re-enable it.

















Tip # 7 - Break into code on handled exceptions
The debugger breaks into your code on unhandled exceptions. However, handled exceptions can also be a source of bugs and you may want to investigate when they occur. We can configure the debugger to break into code for handled exceptions as well by configuring options in the Exception Settings dialog box. Open this dialog box by choosing Debug > Windows > Exception Settings. Also in the dialog box window you can search your relevant exception in which you want to break the code when exception occur.











Reference Link: 
1- Tips & Trick to debug in visual studio
2- Visual Studio Debugging Tips That Will Lighten Your Load

Monday 14 May 2018

How to change tile count at runtime through X ++ code in AX7 / D365

In D365 workspace Tile count is a graphical representation of showing a quick status of information. In tile count there are two ways to show records count. One way is to provide query to tile count and the other way is to write code that returns the tile count. In this blog I will discuss how you can show tile count through code.

Step 1:
Override getData() method of your tile count as shown in image.














Step 2:
After overriding method simply call 
strTileData() method and pass your value in this method as show in image.


That is all you want to do in order to show records count through code.

Key Updates in Dynamics 365 F&O for Version 10.0.39

Here’s a concise summary of the  platform updates  in  Microsoft Dynamics 365 Finance & Operations version 10.0.39 (March 2024) : 1- Add...