Simple SSRS RDL based report, AX classes

Create query
Create SSRS report and add created query as a datasource
If specific parameters at report dialog are not required, then Controller, UIBuilder and Contract classes are not required.
Simple parameters can be added to DataSource.Ranges node of the query and they automatically will appear in the dialog.

Controller:
public class VKSupplierBankAccAuditController extends SrsReportRunController
{
    #define.supplierBankAccountAuditReportName('VKSupplierBankAccAudit.Report')
    #define.parameterVendAccount('VendAccount')
    #define.parameterFromDate('FromDate')
    #define.parameterToDate('ToDate')
}
protected void preRunModifyContract()
{
    SrsReportRdlDataContract        rdlContract = this.parmReportContract().parmRdlContract();
    Query                           query = this.getFirstQuery();
    QueryBuildDataSource            qbds;

    VendAccount                     vendAccount = rdlContract.getParameter(#parameterVendAccount).getValueTyped();
    date                            fromDate = rdlContract.getParameter(#parameterFromDate).getValueTyped();
    date                            toDate = rdlContract.getParameter(#parameterToDate).getValueTyped();

    qbds = query.dataSourceTable(tableNum(VKSupplierBankAccountLog));

    if (vendAccount)
    {
        qbds.addRange(fieldNum(VKSupplierBankAccountLog, VendAccount)).value(SysQuery::value(vendAccount));
    }

    if (fromDate || ToDate)
    {
        // set date range on user role change log according to the selected date range
        SrsReportHelper::addFromAndToDateRangeToQuery(
            query,
            fromDate,
            ToDate,
            tableNum(VKSupplierBankAccountLog),
            fieldNum(VKSupplierBankAccountLog, ActiveDate));
    }
}
public static VKSupplierBankAccAuditController construct(Args _args)
{
    VKSupplierBankAccAuditController controller = new VKSupplierBankAccAuditController();

    if (!_args)
    {
        throw error(Error::missingParameter(null));
    }

    controller.parmReportName(#supplierBankAccountAuditReportName);
    controller.parmArgs(_args);

    return controller;
}
public static void main(Args args)
{
    VKSupplierBankAccAuditController::construct(args).startOperation();
}
Contract:
Parameters with same names should be added to root Parameters node of the report in Visual Studio

[
    SrsReportNameAttribute(ssrsReportStr(VKSupplierBankAccAudit, Report)),
    SysOperationContractProcessingAttribute(classstr(VKSupplierBankAccAuditUIBuilder),
        SysOperationDataContractProcessingMode::CreateUIBuilderForRootContractOnly)
]
class VKSupplierBankAccAuditRdlContract extends SrsReportRdlDataContract
{
    VendAccount                     vendAccount;
    TransDate                       fromDate;
    TransDate                       toDate;

    #define.parameterVendAccount('VendAccount')
    #define.parameterFromDate('FromDate')
    #define.parameterToDate('ToDate')
}
UIBuilder:
[
    SrsReportNameAttribute(ssrsReportStr(VKSupplierBankAccAudit, Report)),
    SysOperationContractProcessingAttribute(classstr(VKSupplierBankAccAuditUIBuilder), SysOperationDataContractProcessingMode::CreateUIBuilderForRootContractOnly)
]
public class VKSupplierBankAccAuditUIBuilder extends SrsReportDataContractUIBuilder
{
    VKSupplierBankAccAuditRdlContract  rdlContract;

    DialogField     dialogVendAccount;
    DialogField     dialogFromDate;
    DialogField     dialogToDate;

    #define.parameterVendAccount('VendAccount')
    #define.parameterFromDate('FromDate')
    #define.parameterToDate('ToDate')
}
public void build()
{
    Dialog      parameterDialog = this.dialog();

    rdlContract = this.getRdlContract();

    dialogVendAccount = parameterDialog.addFieldValue(extendedTypeStr(VendAccount), rdlContract.getValue(#parameterVendAccount));
    dialogFromDate = parameterDialog.addFieldValue(extendedTypeStr(FromDate), rdlContract.getValue(#parameterFromDate));
    dialogToDate = parameterDialog.addFieldValue(extendedTypeStr(ToDate), rdlContract.getValue(#parameterToDate));
}
public void getFromDialog()
{
    rdlContract.setValue(#parameterFromDate, DateTimeUtil::newDateTime(dialogFromDate.value(), 0));
    rdlContract.setValue(#parameterToDate, DateTimeUtil::newDateTime(dialogToDate.value(), 0));
    rdlContract.setValue(#parameterVendAccount, dialogVendAccount.value());
}
public VKSupplierBankAccAuditRdlContract getRdlContract()
{
    return this.getRdlContractInfo().dataContractObject() as VKSupplierBankAccAuditRdlContract;
}
public void preBuild()
{
    date    defaultFromDate;
    date    defaultToDate;

    super();

    // if there are no SysLastValue's for the date range, then default them

    rdlContract = this.getRdlContract();

    defaultFromDate = rdlContract.getValue(#parameterFromDate);
    defaultToDate = rdlContract.getValue(#parameterToDate);

    if (! defaultFromDate || ! defaultToDate)
    {
        rdlContract.setValue(#parameterFromDate, today() - 30);
        rdlContract.setValue(#parameterToDate, today());
    }
}

Output menu item:
ObjectType: Class
Object: VKSupplierBankAccAuditController
LinkedPermissionType: SSRSReport
LinkedPermissionObject: OurCreatedReport
LinkedPermissionObjectChild: Report (design)

If running without Controller, UIBuilder and Contract classes then:
ObjectType: SSRS
Object: OurCreatedReport

Parameter list from contract class: \Classes\SrsReportRunRdlParser\initRdlAndRdpParametersMap: line 12
Standard example: AssetBasisController*
Classes: AssetBasisRdlContract, AssetBasisUIBuilder, AssetBasisController
Query: AssetBasis
SSRS: AssetBasis

Search

About

DaxOnline.org is free platform that allows you to quickly store and reuse snippets, notes, articles related to Dynamics AX.

Authors are allowed to set their own AdSense units.
Join us.

Blog Tags