April 21, 2023

Deploy SSRS Reports using PowerShell – D365FO

Open windows powershell in administrator mode.

execute below commands.

Set-ExecutionPolicy Unrestricted
Y
For Local environment
K:\Packages\Plugins\AxReportStartVmRoleStartupTask\DeployAllReportsToSSRS.ps1

For Azure environment

C:\AosService\PackagesLocalDirectory\Plugins\AxReportVmRoleStartupTask\DeployAllReportsToSSRS.ps1 -PackageInstallLocation "K:\AosService\PackagesLocalDirectory"

X++ code to get List of tables and fields and methods available on table

We might get some scenarios to get the list of objects or a list of elements available in a particular object in X++. Here is a sample piece of code to retrieve the details about the table object.

Whenever we try to get the metadata of an object (Tables, Table fields, 

table methods) we should keep in mind to use the below namespace in our code.

using Microsoft.Dynamics.AX.Metadata.MetaModel;

To get list of tables

using Microsoft.Dynamics.AX.Metadata.MetaModel;
public class TableNamesList
{
    public static void getTableNames()
    {
       var tables = Microsoft.Dynamics.Ax.Xpp.MetadataSupport::GetAllTables();
        var tablesEnumr = tables.GetEnumerator();
        while (tablesEnumr.MoveNext())
        {
            info(strfmt("%1", axTable.Name));
        }
    }
}


To get list of Fields from a table

public static void getFieldNames()
    {
        AxTable table =     Microsoft.Dynamics.Ax.Xpp.MetadataSupport::GetTable(tableId2Name(tablenum(SalesTable)));
       var fields = table.Fields;
        var fieldEnumerator = fields.GetEnumerator();
        while (fieldEnumerator.MoveNext())
        {
            info(strfmt("%1", field.Name));
        }
    }


To get list of methods available on a table

public static void getMethodNames()
    {
        AxTable table = Microsoft.Dynamics.Ax.Xpp.MetadataSupport::GetTable(tableId2Name(tablenum(SalesTable)));
        var methods = table.Methods;
        var methodEnumerator = methods.GetEnumerator();
        while (methodEnumerator.MoveNext())
        {
            AxMethod method = methodEnumerator.Current;
            if(method.IsDisplay)
            {
                info(strfmt("Display method : %1", method.Name));
            }
            else
            {
                info(strfmt("Normal method : %1", method.Name));
            }
        }
    }

Similar to the above code, we can use the metadata .dll in X++ 

to get all the objects and its related details available in AOT 

April 18, 2023

Module ‘xxxx’ has invalid reference to module ‘xxx’ that can cause circular dependencies. This is an indication that the model store is in a broken state.

 


Circular References

Circular dependencies occur when you have two models that both reference objects defined in each other. The system will not allow you to add a reference to a Package/Model that already has a reference to current Model.

As a Dynamics 365 FO developer, you might come across the following error.
Module ‘xxxx’ has invalid reference to module ‘xxx’ that can cause circular dependencies. This is an indication that the model store is in a broken state.

As a developer we would often be moving objects from one environment to another. This moves models alongside. This error therefore occurs when the receiving VM is missing a reference model. While creating a new model in D365FO a descriptor file is generated with the reference model.

To resolve this issue. We will locate this descriptor file and edit it.



Remove the line, save and refresh model from Visual studio.

April 14, 2023

Deploy SSRS reports through command line in D365 FO

Deployment of reports in D365 FO can be done using Visual studio. But there is also another way through which we can deploy report faster.

We can use the Windows PowerShell in the environment to deploy the reports faster and easier. Below are the steps to deploy the reports using Windows PowerShell in D365 FO 


1. Open Windows PowerShell as Administrator

2. Use the below command to navigate to the folder

  • CD K:\AosService\PackagesLocalDirectory\Plugins\AxReportVmRoleStartupTask
3. Use the below command to deploy the reports.
  • All Reports. 
    • DeployAllReportsToSSRS.ps1 -PackageInstallLocation “K:\AosService\PackagesLocalDirectory”
  • Specific Reports
    • DeployAllReportsToSSRS.ps1 -Module ApplicationSuite -ReportName AssetDep*,TaxVatRegister.Report -PackageInstallLocation “K:\AosService\PackagesLocalDirectory”

April 13, 2023

Caching display Methods in X++ - D365 FO

 The performance of display methods can be improved by caching them if they are calculated on Application Object Server (AOS). Caching display methods can also improve performance when records are transferred from the server to the client.

The value of all cached methods is set when data is fetched from the back-end database. In addition, the value is refreshed when the reread method is called on the form data source.

Add a display Method to the Cache

  1. Locate the form that the method is used on.

  2. Expand the Data Sources node.

  3. Right-click the data source that the method is associated with, and then select Override Method > init.

  4. Call the FormDataSource.cacheAddMethod method after the call to super() in the init method.

    The first parameter for cacheAddMethod determines the name of the method to be cached. The second parameter (set to true by default) determines whether the value of the display method is updated when a record is written to the database.

[SysClientCacheDataMethodAttribute(true)] public display Reasoncode display_ReasonCode() { reasoncode ret = ''; ....... return ret; }

April 07, 2023

Warning BP Rule: [BPEmptyCompoundStatement]: Empty Compound statement {...}

  For empty catches, you can use the method ExceptionTextFallThrough to avoid BP warning.

//Call this method to acknowledge the text in the exception should fallthrough

//and eventually be caught by the infolog.

//Example:

try

{

}

catch

{

    ExceptionTextFallThrough();

}