Tuesday, 11 February 2014

SSRS Report Code in AX 2012

Define Data Contract Class:-
[DataContractAttribute]
public class SrsRDPContractSample
{
    AccountNum accountNum;
    Name       name;
    Phone      phone;
}
[DataMemberAttribute("AccountNum")]
public AccountNum parmAccountNum(AccountNum _accountNum = accountNum)
{
    accountNum = _accountNum;
    return accountNum;
}
[DataMemberAttribute("Name")]
public Name Name (Name _name = name)
{
    name = _name ;
    return name;
}
[DataMemberAttribute("InclTax")]
public Phone phone(Phone_phone = phone)
{
    phone= _phone;
    return phone;
}
Now Define Report Data Provider Class:-
[
    SRSReportQueryAttribute('Cust'),
    SRSReportParameterAttribute(classstr(SrsRDPContractSample))
]
public class SrsRdpSampleClass extends SRSReportDataProviderBase
{
    TmpCustTableSample tmpCust;
}
[SRSReportDataSetAttribute('TmpCust')]
public TmpCustTableSample getTmpCustTable()
{
    select * from tmpCust;
    return tmpCust;
}

public void processReport()
{
    AccountNum              accntNum;
    CustAccountStatement    custAcctStmt;
    boolean                 boolInclTax;
    Query                   query;
    QueryRun                qr;
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildRange         queryBuildRange;
    CustTable               queryCustTable;

    SrsRdpContractSample    dataContract;

    // Get the query from the runtime using a dynamic query.
    query = this.parmQuery();
        
    // Get the parameters passed from runtime.
    dataContract = this.parmDataContract();
    accntNum = dataContract.parmAccountNum();
    Name= dataContract.parmName();
    Phone= dataContract.parmPhone();
        
    // Add parameters to the query.
    queryBuildDataSource = query.dataSourceTable(tablenum(CustTable));
        
    if(accntNum)
    {
        queryBuildRange = queryBuildDataSource.findRange(fieldnum(CustTable, AccountNum));
        if (!queryBuildRange)
        {
            queryBuildRange = queryBuildDataSource.addRange(fieldnum(CustTable, AccountNum));
        }
        // If an account number has not been set, then use the parameter value to set it.
        if(!queryBuildRange.value())
            queryBuildRange.value(accntNum);
    }        
        
    if(name)
    {
        queryBuildRange = queryBuildDataSource.findRange(fieldnum(CustTable, Name));
        if (!queryBuildRange)
        {
            queryBuildRange = queryBuildDataSource.addRange(fieldnum(CustTable, Name));
        }
        // If an account statement has not been set, then use the parameter value to set it.
        if(!queryBuildRange.value())
            queryBuildRange.value(int2str(name));
    }
        
    if(phone)
    {
        queryBuildRange = queryBuildDataSource.findRange(fieldnum(CustTable, phone));
        if (!queryBuildRange)
        {
            queryBuildRange = queryBuildDataSource.addRange(fieldnum(CustTable, phone));
        }
        // If flag to include tax has not been set, then use the parameter value to set it.
        if(!queryBuildRange.value())
            queryBuildRange.value(phone);
    }        
        
    // Run the query with modified ranges.
    qr = new QueryRun(query);
    ttsbegin;
    while(qr.next())
    {
        tmpCust.clear();
        queryCustTable = qr.get(tablenum(CustTable));
        tmpCust.AccountNum = queryCustTable.AccountNum;
        tmpCust.Name = queryCustTable.name();
        tmpCust.Phone= queryCustTable.phone();
        tmpCust.insert();
    }
    ttscommit;
} 

No comments:

Post a Comment