Showing posts with label Parameter. Show all posts
Showing posts with label Parameter. Show all posts

Thursday, April 11, 2019

pass temporary data from Ax 2012 to SSRS

I would like to talk a little bit about the SRSTmpTblMarshaller class.
For those who doesn’t know yet, this class makes it possible to share existing temporary data between an AX object and the SSRS.
There are several ways in which you could use a temporary table with the SRSS, but let’s consider the following scenario:
Your report will be printed through a form button and that form uses a temporary table as DataSource. This data can also be manipulated by the user, so you cannot reprocess this data with the DataProvider class.
Instead of turning the temporary table (InMemory) in a regular table – I’ve saw some people doing that, you can use the SRSTmpTblMarshaller as a way batter alternative:
    1. In your contract class, you need to create an accessor method do keep this recordId from the SrsTmpDataStore or you can simply extend the SrsTmpTblMarshallerContract that already have this.
    2. In your controller class, you need to call the sendTmpTblToDataProvid method using your table buffer as parameter. This will store your table buffer as a container inside the SrsTmpDataStore table and return the recordId: protected void preRunModifyContract()
      {
          SrsTmpTblMarshallerContract contract = this.parmReportContract().parmRdpContract() as SrsTmpTblMarshallerContract;
       
          // get the Temp table, and marshall it across to SSRS
          new SRSReportRunPermission().assert();
       contract.parmTmpTableDataRecId(SRSTmpTblMarshaller::SendTmpTblToDataProvider(bankReconciliationPrintoutTmp));
      }​
    3. Request permission by using the assert method in the  SRSReportRunPermission class
    4. Set the recordId inside the accessor method that you’ve created.
    5. Then in your data provider class you can unpack your table buffer using the method getTmpTbl from SRSTmpTblMarshaller class using as parameters the recordId from the SrsTmpDataStore table that you kept in your contract:
      private void initBankReconciliationPrintoutTmp()
      {
          SrsTmpTblMarshallerContract contract = this.parmDataContract()as SrsTmpTblMarshallerContract;
          //Temp Table Object that was returned from SRSDataCarrier
          new SRSReportRunPermission().assert();
          bankReconciliationPrintoutTmp = SRSTmpTblMarshaller::getTmpTbl(contract.parmTmpTableDataRecId());
          SRSTmpTblMarshaller::deleteTmpTblData(contract.parmTmpTableDataRecId());
          CodeAccessPermission::revertAssert();
      }​
    6. Remove your buffer from the scope using the deleteTmpTblData method.
    7. You can also check the BankReconcilliation report. It’s a good example on how to use this functionality. 

Saturday, March 30, 2019

AX2012 Print Dynamic Parameters

in addition to parameters specified in data contracts, reports can also use queries. It’s very handy, because users can specify filters and sorting in exactly the same way as they’re used to from other places in Dynamics AX, they can use query expressions and so on.

A relative common request is printing parameter values on the report itself. It’s easy with parameters defined in data contracts – an expression like =Parameters!UsersToInclude.Value will do the job. But the same approach doesn’t work with dynamic parameters (that’s how query parameters get represented in SSRS).
I recommend the following approach. Use a report data provider class – very often, it’s already in place. Add a new data table to hold information about query ranges and expose it to the report. I’m using an existing table, TmpSysQuery, so we don’t have to discuss the design of the table. In processReport(), we extract ranges from the current query and save them to our temporary table.


class LedgerJournalPostControlDP extends SRSReportDataProviderBase
{
   
    TmpSysQuery tmpSysQuery;
}
 
[SRSReportDataSetAttribute(tablestr(TmpSysQuery))]
public TmpSysQuery getTmpSysQuery()
{
    select tmpSysQuery;
    return tmpSysQuery;
}
 
public void processReport()
{
   
    tmpSysQuery = MyQueryUtils::rangesToTable(this.query());
}

public static TmpSysQuery rangesToTable(Query _query)
{
    QueryBuildDataSource    qbds;
    QueryBuildRange         queryBuildRange;
    TmpSysQuery             tmpSysQuery;
    LabelType               tableLabel;
    int                     occurrence;
    int                     dataSourceNo;
    int                     i;
 
    if (!_query)
    {
        return tmpSysQuery;
    }
 
    for (dataSourceNo = 1; dataSourceNo <= _query.dataSourceCount(); dataSourceNo++)
    {
        qbds = _query.dataSourceNo(dataSourceNo);
        if (qbds.enabled())
        {
            occurrence = SysQuery::tableOccurrence(_query, qbds.table(), dataSourceNo);
            tableLabel = tableId2pname(qbds.table()) + SysQuery::tableOccurrenceText(occurrence);
 
            for (i = 1; i <= qbds.rangeCount(); i++)
            {
                queryBuildRange = qbds.range(i);
 
                if (queryBuildRange.value() && queryBuildRange.status() != RangeStatus::Hidden)
                {
                    tmpSysQuery.clear();
                    tmpSysQuery.DataSourceNo = qbds.uniqueId();
                    tmpSysQuery.TableLabel   = tableLabel;
                    tmpSysQuery.FieldLabel   = fieldId2pname(qbds.table(), queryBuildRange.field());
                    tmpSysQuery.RangeValue   = queryBuildRange.value();
                    tmpSysQuery.insert();
                }
            }
        }
    }
 
    return tmpSysQuery;
}

Then we add a new data set in our report and show query ranges in a tablix in exactly the same way as other data: