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();

}

March 16, 2023

Data Migration Tool - Migrate data from AX2009 to D365 FO

HI All,

I have created a detailed document on DMT tool, please find the document in below link

DMT document 

Thanks,

Shwetha

March 15, 2023

File Import and Export - D365 FO

using System.IO;

using OfficeOpenXml;

using OfficeOpenXml.ExcelPackage;

using OfficeOpenXml.ExcelRange;

using OfficeOpenXml.Style;

using OfficeOpenXml.Table;

class Export_And_Import extends RunBase

{

    //Export Template

    public void ExportData()

    {

        MemoryStream    memoryStream = new MemoryStream();

        using (var package = new ExcelPackage(memoryStream))

        {

            var                         currentRow          = 1;

            var                         worksheets          = package.get_Workbook().get_Worksheets();

            var                         Worksheet           = worksheets.Add("Other Pay Elements");

            var                         cells               = Worksheet.get_Cells();

            OfficeOpenXml.ExcelRange    cell;                

            System.String               value;               

            

            cell    = cells.get_Item(currentRow, 1);

            cell.set_Value("Employee Id");

            

            cell    = cells.get_Item(currentRow, 2);

            cell.set_Value("Month");

            

            cell    = cells.get_Item(currentRow, 3);

            cell.set_Value("Year");


            cell    = cells.get_Item(currentRow, 4);

            cell.set_Value("Date");


            cell    = cells.get_Item(currentRow, 5);

            cell.set_Value("Addition / Deduction");


            cell    = cells.get_Item(currentRow, 6);

            cell.set_Value("Pay Element Code");

            

            cell    = cells.get_Item(currentRow, 7);

            cell.set_Value("Payroll Amount");

            package.Save();

            file::SendFileToUser(memoryStream, "Other Pay Elements Import.xlsx");

        }

    }


    //Import Data

    public void ImportData()

    {

        System.IO.Stream            stream;

        ExcelSpreadsheetName        sheeet;

        FileUploadBuild             fileUpload;

        DialogGroup                 dlgUploadGroup;

        FileUploadBuild             fileUploadBuild;

        FormBuildControl            formBuildControl;

        Dialog                      dialog = new Dialog("Import Pay Elements");

        str                         ctrl = "Import";

        PayElements                 payElements;

        AddDeduct                   addDeduct;


        dlgUploadGroup          = dialog.addGroup("@SYS54759");

        formBuildControl        = dialog.formBuildDesign().control(dlgUploadGroup.name());

        fileUploadBuild         = formBuildControl.addControlEx(classstr(FileUpload), ctrl);

        fileUploadBuild.fileTypesAccepted('.xlsx');


        if (dialog.run() && dialog.closedOk())

        {

            FileUpload                       fileUploadControl     = dialog.formRun().control(dialog.formRun().controlId(ctrl));

            FileUploadTemporaryStorageResult fileUploadResult      = fileUploadControl.getFileUploadResult();


            if (fileUploadResult != null && fileUploadResult.getUploadStatus())

            {

                stream = fileUploadResult.openResult();


                using (ExcelPackage Package = new ExcelPackage(stream))

                {

                    int                         rowCount, i;

                    Package.Load(stream);

                        

                    ExcelWorksheet              worksheet   = package.get_Workbook().get_Worksheets().get_Item(1);

                    OfficeOpenXml.ExcelRange    range       = worksheet.Cells;

                    rowCount                                = worksheet.Dimension.End.Row - worksheet.Dimension.Start.Row + 1;


                    for (i = 2; i<= rowCount; i++)

                    {

                        select payElements where payElements.EmplId           == range.get_Item(i, 1).value

                                                   && payElements .PayElementCode   == range.get_Item(i, 6).value

                                                   && payElements .EffectiveDate    == DateTimeUtil::date(range.get_Item(i, 4).value);

                        if(!payElements )

                        {

                            payElements .EmplId         = range.get_Item(i, 1).value;

                            payElements .PayslipMonth   = str2Int(range.get_Item(i, 2).value);

                            payElements .PayslipYear    = str2Int(range.get_Item(i, 3).value);

                            payElements .EffectiveDate  = DateTimeUtil::date(range.get_Item(i, 4).value);

                            payElements .AddDeduct      = str2Enum(addDeduct,range.get_Item(i, 5).value);

                            payElements .PayElementCode = range.get_Item(i, 6).value;

                            payElements .Amount         = any2Real(range.get_Item(i, 7).value);

                            payElements .insert();

                        }

                        else

                        {

                            continue;

                        }

                    }

                    info("Pay Elements Imported");

                }

            }

            else

            {

                error("File was not Loaded Properly");

            }

        }

    }


    public static void main(Args args)

    {

        PayElementsImport objimport = new PayElementsImport ();


        DialogButton         dialogButton;


        dialogButton   =    Box::yesNo("Create Empty Excel",DialogButton::Yes,"Empty Excel","Yes OR No");


        if(dialogButton == DialogButton::Yes)

        {

            objimport.ExportData();

        }

        objimport.ImportData();

    }

}

To Get & Set Unbound Control Values from a Form Extension, perform action on Controls

Example::

[FormDataSourceEventHandler(formDataSourceStr(CustTable, CustTable), FormDataSourceEventType::Activated)]

public static void CustTable_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)

{

    CustTable           custTable     = sender.cursor(); //selected record

    FormDataSource      custTable_ds  = sender.formRun().dataSource("CustTable"); //DataSource form CustTable

    FormRun             element       = sender.formRun(); //form element

    FormControl         myNewButton   = element.design(0).controlName("MyNewButton"); //New button on the form


    FormStringControl         strResult;

    FormRealControl realResult;

    FormIntControl         intResult;

    FormDateControl dateResult;

    FormComboBoxControl comboResult;


    //To Get DataSource Current Record of a Field

    custTable.AccountNum = XXX.valueStr();

    //Str

    strResult = element.design().control(element.controlId("strResult"));

    //Set

    strResult.text("this is what it should say");

    //Get

    strResult.valueStr();


    //Real

    realResult = element.design().control(element.controlId("realResult"));

    //Set

    realResult.realValue(50.05);

    //Get

    realResult.value();


    //Integer

    intResult = element.design().control(element.controlId("intResult"));

    //Set

    intResult.value(50);

    //Get

    intResult.value();


     //Date

     dateResult = element.design().control(element.controlId("dateResult"));

     //Set

     dateResult.dateValue(today());

     //Get

     dateResult.dateValue();


     //Date

     comboResult = element.design().control(element.controlId("comboResult"));

     //Set

     comboResult.selection(1);

     //Get

    comboResult.valueStr(); //Convert to Enum to Str

    myNewButton.enabled(false); //Here you do your code to enabled or disabled the button

}

March 14, 2023

Change SSRS Report Labels language depend on the Vendor language Id

 Go to

preRunModifyContract() override Method in Controller class and add the below code

CODE:

this.parmReportContract().parmRdlContract().parmLanguageId(VendTable::find(vendPurchOrderJour.OrderAccount).languageId());

That’s all !!!!