Saturday, 27 September 2014

CSV supported AX SSRS reports

CSV supported AX SSRS reports
It’s a common ask that user wants to export csv file from the report generated. The immediate feedback would be extra columns or columns which shows something like textbox1 or textbox2…

It’s better to develop CSV supported report at start itself to avoid the modification later.

What does CSV prints?

All fields in your rdl which has Data Element Output as Auto or Output


The column will have values of the field where as column header will have value of “DataElementName” or “Name” property of the textbox field.

How does CSV Work?
CSV just prints the value of each text box as columns in excel headed by text box name as column header.
The column headers which we use in report does also considered to be label as values text box name as textbox control name. Which creates unnecessary columns in csv output.

Anything CSV does not print?
Yes . All fields in your rdl which has Data Element Output as NoOutput.

And Now How to Make SSRS Report CSV Supported
·         Give valid name for the text box which has values instead of default naming like textbox1, textbox2 etc.
·         All textboxes which prints the label should have data element output property as NoOutput
·         All textboxes which prints the totals , title should be set to property NoOutput.







Adding parameter to AX SSRS Report

Adding RDP parameter to report
Let us see how to add parameter to existing report. We will take up customer transaction report and add from date and to date as parameters.
Step 1: Create 2 parm methods in CustTransListContract
 For FromDate and ToDate
/// <summary>
/// Gets or sets the value of the datacontract parameter FromDate.
/// </summary>
/// <param name="_fromDate">
/// The new value of the datacontract parameter FromDate; optional.
/// </param>
/// <returns>
/// The current value of datacontract parameter FromDate.
/// </returns>
[
    DataMemberAttribute('FromDate'),
    SysOperationHelpTextAttribute(literalStr("@SYS26930"))
]
public FromDate parmFromDate(FromDate _fromDate = fromDate)
{
    fromDate = _fromDate;
    return fromDate;
}

/// <summary>
/// Gets or sets the value of the datacontract parameter ToDate.
/// </summary>
/// <param name="_toDate">
/// The new value of the datacontract parameter ToDate; optional.
/// </param>
/// <returns>
/// The current value of datacontract parameter ToDate.
/// </returns>
[
    DataMemberAttribute('ToDate'),
    SysOperationHelpTextAttribute(literalStr("@SYS26929"))
]
public ToDate parmToDate(ToDate _toDate = toDate)
{
    toDate = _toDate;
    return toDate;
}


Step 2: Check for initialisation code in processReport method of CustTransListDP class
  contract = this.parmDataContract() as CustTransListContract;

Step 3: Assign the parameter value to local variable and use it for filtering in process report.
FromDate FromDate;
ToDate  ToDate;

fromDate = contract.parmDate();
toDate   = contract.ToDate();

if ((cursor.TableId == custTable.TableId ||
                    !(remainAmount &&
                (custTrans.CurrencyCode ? custTrans.AmountCur == custTrans.SettleAmountCur : custTrans.AmountMST == custTrans.SettleAmountMST))) &&
                (custTrans.TransType != LedgerTransType::ExchAdjustment ||
                (custTrans.TransType == LedgerTransType::ExchAdjustment && this.balanceMST(exchangeAdjustmentType) != 0)) && (custInvoiceJour.InvoiceDate >= fromdate && custInvoiceJour.InvoiceDate <= toDate) )

{
// insertion code as is
}


Step 4: Add fromDate and ToDate form control(dialog control) in form(dialog) for end user input in CustTransListUIBuilder-> build method.

    FromDateField          = this.bindInfo().getDialogField(custTransListContract, methodStr(CustTransListContract, parmfromDate));
ToDateField          = this.bindInfo().getDialogField(custTransListContract, methodStr(CustTransListContract, parmToDate));




               
Step 5:Compile forward the contract class,UI builder and DP classes which were updated before.
Step 6: Open the report design in visual studio and check the parameters node available for fromDate and toDate




If Available,
Build and Deploy the report.
If parameter is unavailable then
                Delete CustTransListDS datasource in report


               
Right click datasets and add new dataset . Update the properties as below.

Click the continue button in property section in Query control. DP selection window will open.


Select CustTransListDP and all fields . Click next  and finish the wizard.
Redeploy the report.
Step 6: Delete report from report manager site.
Report manager url is available at following location.
System Administration -> Setup-> Business Intelligence -> Reporting Services-> Report servers
Redeploy the report.
Restart AOS.
Restart SSRS service.