24 November 2020

Contract class example for SSRS report in D365FO

 Controller class example


/// TRG_AgedReceivables

/// <summary>

/// Controller class for Aged receivables report

/// </summary>

class TRG_SalesSummaryController extends SrsReportRunController

{

   


    public static TRG_SalesSummaryController construct()

    {

        return new TRG_SalesSummaryController();

    }


    public static void main(Args arg)

    {

        TRG_SalesSummaryController controller = TRG_SalesSummaryController::construct();

        

        controller.parmReportName(ssrsReportStr(TRG_SalesSummaryCurrencyReport, PrecisionDesign1));

        controller.parmArgs(arg);


        controller.startOperation();

    }


    protected void preRunModifyContract()

    {

        TRG_SalesSummaryContract   dataContract;

        

        TRG_SalesSummaryParameter TRG_SalesSummaryParameter;

        TRG_SalesSummary reportType;


        super();


        dataContract = this.parmReportContract().parmRdpContract() as TRG_SalesSummaryContract;


        reportType = dataContract.parmReportType();


        delete_from TRG_SalesSummaryParameter;


        TRG_SalesSummaryParameter.Fromdate =dataContract.parmFromDate();

        TRG_SalesSummaryParameter.Todate=dataContract.parmToDate();

        TRG_SalesSummaryParameter.Division=dataContract.parmDivisionId();

        TRG_SalesSummaryParameter.Category=dataContract.parmCategoryId();

        TRG_SalesSummaryParameter.Itemid=dataContract.parmItemId();

        TRG_SalesSummaryParameter.Warehouse=dataContract.parmInventLocationId();

        TRG_SalesSummaryParameter.Site = dataContract.parmInventSiteId();

        TRG_SalesSummaryParameter.Customer = dataContract.parmCustAccount();

        TRG_SalesSummaryParameter.SalesGroup= dataContract.parmCommissSalesGroup();

        TRG_SalesSummaryParameter.insert();

       

       

        switch (reportType)

        {

            case TRG_SalesSummary::Customer:

                this.getReportContract().parmReportName(ssrsReportStr(TRG_SalesSummaryCustomerReport, PrecisionDesign1));

                this.parmReportName(ssrsReportStr(TRG_SalesSummaryCustomerReport, PrecisionDesign1));

                break;


            case TRG_SalesSummary::Currency:

                this.getReportContract().parmReportName(ssrsReportStr(TRG_SalesSummaryCurrencyReport, PrecisionDesign1));

                this.parmReportName(ssrsReportStr(TRG_SalesSummaryCurrencyReport, PrecisionDesign1));

                

                break;

        }


       

    }


}


===========================================================



/// TRG_AgedReceivables

/// <summary>

/// Controller class for Aged receivables report

/// </summary>

class TRG_InvoiceHistoryController extends SrsReportRunController

{

   


    public static TRG_InvoiceHistoryController construct()

    {

        return new TRG_InvoiceHistoryController();

    }


    public static void main(Args arg)

    {

        TRG_InvoiceHistoryController controller = TRG_InvoiceHistoryController::construct();

        

        controller.parmReportName(ssrsReportStr(TRG_InvoiceHistory, DetailByEachBillingWithCost));

        controller.parmArgs(arg);


        controller.startOperation();

    }


    protected void preRunModifyContract()

    {

        TRG_InvoiceHistoryContract   dataContract;


        TRG_SalesSummaryParameter TRG_SalesSummaryParameter;

        TRG_InvoiceHistory reportType;


        super();


        dataContract = this.parmReportContract().parmRdpContract() as TRG_InvoiceHistoryContract;


        reportType = dataContract.parmReportType();


        //delete_from TRG_SalesSummaryParameter;


        //TRG_SalesSummaryParameter.Fromdate =dataContract.parmFromDate();

        //TRG_SalesSummaryParameter.Todate=dataContract.parmToDate();

        //TRG_SalesSummaryParameter.Division=dataContract.parmDivisionId();

        //TRG_SalesSummaryParameter.Category=dataContract.parmCategoryId();

        //TRG_SalesSummaryParameter.Itemid=dataContract.parmItemId();

        //TRG_SalesSummaryParameter.Warehouse=dataContract.parmInventLocationId();

        //TRG_SalesSummaryParameter.Site = dataContract.parmInventSiteId();

        //TRG_SalesSummaryParameter.Customer = dataContract.parmCustAccount();

        //TRG_SalesSummaryParameter.SalesGroup= dataContract.parmCommissSalesGroup();

        //TRG_SalesSummaryParameter.insert();



        switch (reportType)

        {

            case TRG_InvoiceHistory::DetailByEachBillingWithCost:

                this.getReportContract().parmReportName(ssrsReportStr(TRG_InvoiceHistory, DetailByEachBillingWithCost));

                this.parmReportName(ssrsReportStr(TRG_InvoiceHistory, DetailByEachBillingWithCost));

                break;


            case TRG_InvoiceHistory::DetailByEachBillingWithOutCost:

                this.getReportContract().parmReportName(ssrsReportStr(TRG_InvoiceHistory, DetailByEachBillingWithOutCost));

                this.parmReportName(ssrsReportStr(TRG_InvoiceHistory, DetailByEachBillingWithOutCost));


                break;

        }



    }


}


05 November 2020

How to get data and time from Excel using X++

Below is code snippet can be used to get the date and time from excel.

 // Convert into str from excel cell value

    str COMVariant2Str(COMVariant cv, int decimals = 0, int characters = 0, int separator1 = 0, int _separator2 = 0)

    {

        switch (_cv.variantType())

        {

            case (COMVariantType::VT_BSTR):

            return _cv.bStr();


            case (COMVariantType::VT_R4):

            return num2str(_cv.float(),_characters,_decimals,_separator1,_separator2);


            case (COMVariantType::VT_R8):

            return num2str(_cv.double(),_characters,_decimals,_separator1,_separator2);


            case (COMVariantType::VT_DECIMAL):

            return num2str(_cv.decimal(),_characters,_decimals,_separator1,_separator2);


            case (COMVariantType::VT_DATE):

            //return date2str(_cv.date(),123,2,1,2,1,4);

            return date2str(_cv.date(),213,2,1,2,1,4)+" "+time2str(_cv.time(),TimeSeparator::Colon, TimeSeparator::Colon);


            case (COMVariantType::VT_EMPTY):

            return '';


            default:

            throw error(strfmt('@SYS26908', _cv.variantType()));

        }

        return '';

    }

21 October 2020

X++ code to get datasource using control event handler in D365FO

FormRun formRun = sender.formRun();

        Object          inventTrans_ds = formRun.dataSource(formDataSourceStr(InventMarking,InventTransOrigin));

{


 FormRun formRun = sender.formRun();

        Object          inventTrans_ds = formRun.dataSource(formDataSourceStr(InventMarking,InventTransOrigin));


InventTransOrigin localInventTrans;

        InventTrans localInventTrans_1;

        for (localInventTrans = inventTrans_ds.getFirst() ? inventTrans_ds.getFirst() : inventTrans_ds.cursor();

        localInventTrans;

        localInventTrans = inventTrans_ds.getNext())

        {

            localInventTrans_1 = InventTrans::findByInventTransOrigin(localInventTrans.RecId);

        }

}

21 August 2020

how to print report for selected Record in D365FO & Running an SSRS report from the selected record D365 F&O

Running an SSRS report from the selected record

class TRGVendAccuredPurchaseController extends SrsReportRunController

{

    public static void Main(Args _args)

    {

        TRGVendAccuredPurchaseController::construct(_args).startOperation();

    }


    public static TRGVendAccuredPurchaseController construct(Args _args)

    {

        TRGVendAccuredPurchaseController controller = new TRGVendAccuredPurchaseController();

        controller.parmReportName(ssrsReportStr(TRGVendAccruedPurchases, Report));

        controller.parmArgs(_args);

        controller.parmLoadFromSysLastValue(false);

        return controller;

    }


    public void prePromptModifyContract()

    {

        FormRun formRun = this.parmArgs().caller();        

        ProjTable projtable = this.parmArgs().record();


        if((formRun) && (formRun.name() == Formstr(ProjTable) || formRun.name() == Formstr(ProjProjectsListPage)))

        {

            SrsReportHelper::addParameterValueRangeToQuery(this.getFirstQuery(),tableNum(PurchTable),fieldNum(PurchTable, ProjId),SysQuery::value(projtable.ProjId));

        }

        super();

    }


}

Working with the calling object of a formcaller in d365FO

 FormRun formRun = this.parmArgs().caller();        

 ProjTable projtable = this.parmArgs().record();


        if((formRun) && (formRun.name() == Formstr(ProjTable) || formRun.name() == Formstr(ProjProjectsListPage)))

        {

            SrsReportHelper::addParameterValueRangeToQuery(this.getFirstQuery(),tableNum(PurchTable),fieldNum(PurchTable, ProjId),SysQuery::value(projtable.ProjId));

        }

03 August 2020

How to get multiple record or selected record in D365FO

Public static void main(Args _args)
{
ProjOnAccTrans  projOnAccTrans;
        FormRun formRun = _args.caller();
        FormDataSource fds;
        fds = formRun.dataSource(formDataSourceStr(ProjTransOnAcc,ProjOnAccTrans));

        projOnAccTrans = fds.getFirst(true);
}

12 March 2020

How to get MainAccount using ledger dimension recId in ax 2012

In the below code have to pass ledgerDimension recId to get the main account Id.

Table.MainAccountId             =   MainAccount::findByLedgerDimension(ledgerDimension).MainAccountId;

01 March 2020

How to extend standard report (Purchase order report ) in D365 F&O using print management / Report extension in D365

Dynamics Ax 365 SSRS: How to call new Report/Design for existing Print management report

To get the report format in the setup Print management setup:
Need to create extension for the PrintMgmtReportFormatPopulator->addDocuments()
Need to add the new report to get the report in the configuration

Step1. Duplicate the PurchPurchaseOrder standard Report as PurchPurchaseOrderADD
Step2. Go to PrintMgmtDocType class and copy the eventHandler delegate method called getDefaultReportFormatDelegate
Step3. Create new class "PrintMgmtDelegatesHandler_Test" and paste the eventHandler.

below is reference code. To execute the report different designs per each legal entity.

Once we done this - Need to go to AP-Setup-Forms->Form setup -> Print Management button then in that form have to select the that related Purchase order report in the dropdown.



class PrintMgmtDelegatesHandler_Test
{
    /// <summary>
    ///
    /// </summary>
    /// <param name="_docType"></param>
    /// <param name="_result"></param>
    [SubscribesTo(classStr(PrintMgmtDocType), delegateStr(PrintMgmtDocType, getDefaultReportFormatDelegate))]
    public static void PrintMgmtDocType_getDefaultReportFormatDelegate(PrintMgmtDocumentType _docType, EventHandlerResult _result)
    {
        PrintMgmtReportFormatName formatName = PrintMgmtDelegatesHandler_Test::getDefaultReportFormat(_docType);
        if (formatName)
        {
            _result.result(formatName);
        }
    }

    private static PrintMgmtReportFormatName getDefaultReportFormat(PrintMgmtDocumentType _docType)
    {

        switch (_docType)
        {
            case PrintMgmtDocumentType::PurchaseOrderRequisition:
                {
                    if(curExt() == "USMF")
                    {
                        return ssrsReportStr(PurchPurchaseOrderADD, Report);
                    }
                    if(curExt() == "RUMF")
                    {
                        return ssrsReportStr(PurchPurchaseOrderADD, ReportRU);
                    }

                }
            case PrintMgmtDocumentType::PurchaseOrderConfirmationRequest:
                {
                    if(curExt() == "USMF")
                    {
                        return ssrsReportStr(PurchPurchaseOrderADD, Report);
                    }
                    if(curExt() == "RUMF")
                    {
                        return ssrsReportStr(PurchPurchaseOrderADD, ReportRU);
                    }
                }
        }
        return '';
    }

}

Need to execute the below job to populate new report design in the Print management setup Table(PrintMgmtReportFormat) can open see new report is inserted in this table or not after executing below populate method.

class PrintPopulateReportFormat
{
    public static void main(Args _args)
    {
        PrintMgmtReportFormatSubscriber::populate();
        
    }
}

Ledger Voucher creation Framework and x++ code to create ledger voucher

 Please click her for MS reference file Below is the out of the box example reference and code. SalesInvoiceJournalPostSubBill_Extension->...