Alfasith AX

Alfasith AX
اللَّهُمَّ انْفَعْنِي بِمَا عَلَّمْتَنِي، وَعَلِّمْنِي مَا يَنْفَعُنِي، وَزِدْنِي عِلْمًا

Friday, July 5, 2013

Controller class in Dynamic AX

Hi,

This controller class is used to print the reports directly instead of passing via param dialog.

class CustController extends SrsReportRunController
{
    #define.ReportName('CustReport.PrecisionDesign1')
    SRSRDPCustTableContractClass sRSRDPCustTableContractClass;
    CustTable custTable ;
 }

/************************************************************************/
public static CustController construct(Args _args)
{
    CustController controller=new CustController();
    controller.parmArgs(_args);
    return controller;
}

/**********************************************************************/
public static void main(Args _args)
{
    CustController controller = new CustController();
    controller.parmReportName(#ReportName);
    controller.parmArgs(_args);
    controller.setRange(_args, controller.parmReportContract().parmQueryContracts().lookup(controller.getFirstQueryContractKey()));
    controller.parmShowDialog(false);
    controller.startOperation();
 }
/****************************************************/
public boolean showQueryValues(str parameterName)
{
    return true;
}
/*****************************************************/
public void setRange(Args _args, Query _query)
{
    QueryBuildDataSource qbds;
    QueryBuildRange qbr;
    if (_args && _args.dataset())
    {
        switch(_args.dataset())
        {
            case tableNum(CustTable) :
                CustTable = _args.record();
                break;
        }
    }
    qbds = _query.dataSourceTable(tableNum(CustTable));
    qbds.clearRanges();
    qbr = qbds.findRange(fieldName2id(tableNum(CustTable),fieldStr(CustTable, AccountNum)));
    if (!qbr)
    {
        qbr = qbds.addRange(fieldNum(CustTable, AccountNum));
    }
    if(CustTable)
    {
        qbr.value(CustTable.AccountNum);
    }
}

/**********************************************************/
protected void prePromptModifyContract()
{
      super();
}

________________________________________________________________
--------------------------------------------------------------------------------------
Another sample controller class..

Controller class:(al khaldi)
 class SIController extends SrsReportRunController
{
  #define.ReportName(‘SIRep.PrecisionDesign1′)
    SIContract SIContract;
    CustInvoiceJour CustInvoiceJour ;
}

 protected void prePromptModifyContract()
{
   /* if (this.parmArgs()             &&
        this.parmArgs().record()    &&
        this.parmArgs().dataset() == tableNum(CustInvoiceTrans))
    {
        CustInvoiceTrans = this.parmArgs().record();
    }
    if (!SIContract)
    {
        SIContract = this.parmReportContract().parmRdpContract();
    }
    SIContract.parmProjectId(projTable.ProjId);
   */
    super();
}

public void setRange(Args _args, Query _query)
{
    QueryBuildDataSource qbds;
    QueryBuildRange qbr;
    if (_args && _args.dataset())
    {
        switch(_args.dataset())
        {
            case tableNum(CustInvoiceJour) :
                CustInvoiceJour = _args.record();
                break;
        }
    }

    qbds = _query.dataSourceTable(tableNum(CustInvoiceJour));

    qbds.clearRanges();

    qbr = qbds.findRange(fieldName2id(tableNum(CustInvoiceJour),fieldStr(CustInvoiceJour, SalesId)));

    if (!qbr)
    {
        qbr = qbds.addRange(fieldNum(CustInvoiceJour, SalesId));
    }
    if(CustInvoiceJour)
    {
        qbr.value(CustInvoiceJour.SalesId);
    }

}

public boolean showQueryValues(str parameterName)
{
    return true;
}
 public static SIController construct(Args _args)
{
    SIController controller=new SIController();
    controller.parmArgs(_args);
    return controller;
}

public static void main(Args _args)
{
    SIController controller = new SIController();
    controller.parmReportName(#ReportName);
    controller.parmArgs(_args);
    controller.setRange(_args, controller.parmReportContract().parmQueryContracts().lookup(controller.getFirstQueryContractKey()));
    controller.parmShowDialog(false);
    controller.startOperation();
 }


Bhanu’s controller class:
Controller :
If  you create Controller class, then you need to create output menu item, set  property Object type – class, Object – Controller class created,  Linked permission type – SSRS report, Linked Permission object – SSRS report Created,  Linked permission object type – Design name.
class ProjHourUtilisationController extends SrsReportRunController
{
  #define.ReportName(‘ProjHourUtilisation.PrecisionDesign1′)
    ProjHourUtilisationContract projHourUtilisationContract;
    ProjTable projTable ;
}


protected void prePromptModifyContract()
{
    if (this.parmArgs()             &&
        this.parmArgs().record()    &&
        this.parmArgs().dataset() == tableNum(ProjTable))
    {
        projTable = this.parmArgs().record();
    }
    if (!projHourUtilisationContract)
    {
        projHourUtilisationContract = this.parmReportContract().parmRdpContract();
    }
    projHourUtilisationContract.parmProjectId(projTable.ProjId);
    super();
}

public void setRange(Args _args, Query _query)
{
    QueryBuildDataSource qbds;
    QueryBuildRange qbr;
    if (_args && _args.dataset())
    {
        switch(_args.dataset())
        {
            case tableNum(ProjTable) :
                projTable = _args.record();
                break;
        }
    }
     qbds = _query.dataSourceTable(tableNum(ProjTable));
     qbds.clearRanges();
     //qbr = qbds.findRange(fieldName2id(tableNum(ProjTable),fieldStr(ProjTable, ProjId)));
     if (!qbr)
    {
        qbr = qbds.addRange(fieldNum(ProjTable, ProjId));
    }
    if(ProjTable)
    {
        qbr.value(projTable.ProjId);
    }

}
public boolean showQueryValues(str parameterName)
{
    return true;}
 public static ProjHourUtilisationController construct(Args _args)
{
    ProjHourUtilisationController controller=new ProjHourUtilisationController();
    controller.parmArgs(_args);
    return controller;
}
public static void main(Args _args)
{
    ProjHourUtilisationController controller = new ProjHourUtilisationController();
    controller.parmReportName(#ReportName);
    controller.parmArgs(_args);
    controller.setRange(_args, controller.parmReportContract().parmQueryContracts().lookup(controller.getFirstQueryContractKey()));
    controller.parmShowDialog(true);
    controller.startOperation();
}

2 comments:

  1. Hello,
    I am trying to print a journal but facing a "Map not initialized" error on the following line:

    controller.setRange(_args, controller.parmReportContract().parmQueryContracts().lookup(controller.getFirstQueryContractKey()));

    in main() function of LedgerJournalController class.

    The function parmQueryContracts() returns "null" instead of a Map.
    Can you help?

    ReplyDelete
  2. Please check this post hope it will solve your problem.

    http://alfasith.blogspot.qa/2013/07/save-ssrs-report-as-pdf-or-print-it.html

    ReplyDelete

How find size of recordsortedlist in D365/AX 2012

Hi, This is the continuity of the previous article where we are now getting the size of recordsortedlist . if(recordsortedlist.len() >1) ...