Do you know all of the D365 development tips and tricks when working with Microsoft Dynamics 365 for Finance and Operations? Find out by watching this video. Two time Microsoft Business Applications MVP Nathan Clouse invited me to co-present with him. And I was honored and thrilled to be asked. Watch as we show you things that will make development easier and more fun. There is so much to learn. So feel free to share what you have found helpful for you.
Nathan Clouse
You likely are very familiar with Nathan. You likely have read his blog and/or heard him speak. He is an incredibly smart and kind guy. And you will learn a lot by listening to what he has to say. Please check out his blog site at atomicax.com. Also checkout www.dynamics.fo.
I highly recommend you just watch the video. Nathan created the content for this presentation and video. I will include a few of the tips in the following paragraphs for reference.
Coding Tips
One of the simplest and frequently used D365 development tips and tricks is how to comment your code using a shortcut. First, select some code. Next, Push Ctrl-K. Then, while still holding down the control key, push the ‘C’ key to comment out the selected code.
To uncomment code, first select some code. Next, push Ctrl-K. Then, while still holding down the control key, push the ‘U’.
This works in most editors, and makes it a lot easier and faster when you need to comment and uncomment code.
Additionally, after selecting some code, push Ctrl-K, then D to format code.
Push F9 to add a breakpoint. Push F9 again to remove a breakpoint.
After putting your cursor on the name of a method, push F12 to take you to the definition of a class.
Copy Event Handlers
As a developer in Microsoft Dynamics 365 for Finance and Operations there are many times when you need to write an event handler. Instead of writing the code from scratch, you can actually have Visual Studio generate the code for you, and put it into your clipboard. You can then paste this code into a new or existing class to behind writing your event handler. This is a really useful d365 development tip and trick that can save you some time, and prevent mistakes.
In the design view, expand methods, right click, then select copy event handler.
Alternatively, in the design view, expand events, right click on an event, and select Copy event handler method.
CrossCompany
The CrossCompany keyword can be used within x++ code. Specifically, using this keyword will cause the system to look at data in all companies (also known as legal entities). Whereas, without this keyword, the select and while select statements will only query data from the current company the user is logged into.
This is useful to add to our D365 Development Tips And Tricks list because many people do not know about this keyword until they are taught.
To explain further, when writing T-SQL, you need to add a clause like this to all of your queries: where dataAreaId = ‘<myCurrentCompany>’. However, when writing select or while select statements, you do not. The system, when it generates the underlying SQL code, automatically adds this where clause for you.
Most of the time, this is very nice. However, there are times when you really do want to search records in all tables. And the CrossCompany keyword will do just that. Look at the following example code:
BankAccountTable tabBAT; // saveDataPerCompany == true.
container conCompanies = [ 'cm1', 'cm2', 'dat' ];
str 4 sCompanyPrevious = " "; // Maximum length is 4 characters.
int iCountCompanies = 0;
;
while select
crossCompany
: conCompanies
* from tabBAT
order by dataAreaId
{
…
}
Here is how you would use crossCompany in a Query:
static void JobDemoAllowCrossCompany(Args _args)
{
BankAccountTable tabBAT; // saveDataPerCompany == true.
Query qry2;
QueryBuildDataSource qbds3;
QueryRun qrun4;
str sCompanyPrevious = " ";
int iCountCompanies = 0;
int iTableNumBAT;
;
qry2 = new Query();
qry2.allowCrossCompany( true );
qry2.addCompanyRange( 'dat' );
qry2.addCompanyRange( 'twf' );
iTableNumBAT = tableNum( BankAccountTable );
qbds3 = qry2 .addDataSource( iTableNumBAT );
//qbds3.company( 'dat' );
qrun4 = new QueryRun( qry2 );
RunAsPermission
RunAsPermisson allows you to run code in the security context of another user. Please checkout the Microsoft documentation here. And look at the following code example:
public static container download(container _parms)
{
RunAsPermission perm;
perm = new RunAsPermission("Admin");
perm.assert();
Container returncontainer = runAs("Admin", classnum(AcxSharepointIntegeration), "get", _parms);
CodeAccessPermission::revertAssert();
return returncontainer;
}
String Runtime Functions
Additionally, for another D365 development tips and tricks item, look at the large list of global runtime functions that you can directly call from within x++. These, in particular are great for working with strings. Whether it be parsing a string, or modifying a string. These will save you a lot of time compared to trying to write these functions yourself.
Use C#
As well as functions that exist within x++, you can call code that is written outside of x++. Specifically, you can actually call .NET code that is written in C# or Visual Basic from within Microsoft Dynamics 365 for Finance and Operations.
This is extremely useful when there is a library that has already been written in .NET that meets your need. Instead of re-coding that class within x++, you can just call that .NET library directly.
For example, I use this functionally regularly when I am dealing with reading files. Or when I need to serialize or de-serialize an object into XML or JSON.
Info Dot Add
This next item from our list of D365 development Tips and Tricks is one of my favorite. Have you ever had trouble discovering where in code an error message is being thrown? I know I have. Put a breakpoint in the Info class’s ‘Add’ method. This method gets called anytime an infolog is printed to a screen. Whether it be info, warning, or error.
Next, attach the debugger, and run your process again. The breakpoint will get hit. And you can look at the call stack in Visual Studio to see what code is printing that message.
Metadata Search
You can use some special syntax to search for specific objects within the Application Explorer window in Visual Studio. Similarly, you can do some searches within the form designs window.
Check out the Microsoft documentation for the details.
Resources
Please check out the following articles for more D365 Development Tips and Tricks, and details on what was covered in this article.
- http://www.atomicax.com/article/d365fotools-and-vs2017-manhattan-project
- https://docs.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/dev-ref/xpp-business-run-time-functions
- https://docs.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/dev-ref/xpp-string-run-time-functions
- https://jatomas.com/en/2020/05/02/dark-mode-visual-studio-x-code-editor/
Conclusion
Thank you again to Nathan for inviting me to present this content with him. I love D365 Development Tips and Tricks. They are fun to show off. Additionally, they help me feel like I know some cool things, that not everyone knows.
Again, I recommend you watch the associated YouTube video as there is a lot more in that video. I hope you learned something new today!