How to move temporary form data to RDP Class of SSRS Report in Dynamics AX

1. Declare a list object in the ClassDeclaration of the temporary form
public class FormRun extends ObjectRun
{
      List   recordList;
}

 2. Override the clicked() method of the OK button in the temporary form. Loop the form data source records and add it to a List. Then call the method printMyReport().

void clicked()

{

    MyTmpTable  myTmpTableLocal;

    recordList = new List(Types::Record);

    myTmpTable_ds.write();

    for (myTmpTableLocal= myTmpTable_ds.getFirst();

           myTmpTableLocal;

           myTmpTableLocal= myTmpTable_ds.getNext())

    {

          recordList.addEnd(myTmpTableLocal);

    }

             element.printMyReport(); 

}

3.  Create a method in Form, called printMyReport() and pass the list object of records as parmObject to send out the temporary form data to the Controller class.

public void printMyReport()

{

    Args args = new Args();

    args.record(myTmpTable);

    args.parmObject(recordList);

    args.caller(element);

    new MenuFunction(menuitemOutputStr(myReport), MenuItemType::Output).run(args);

}

4. Declare a RecId type variable in the Contract class of the report.

public class MyReportContract implements SysOperationValidatable

{

     RecId  tmpDataStoreRecId;

} 

5.  Create a parm method to get/set the value the SRSTmpDataStore table RecId in the report contract class.

[

    DataMemberAttribute('TmpDataStoreRecId')

]

public RecId parmTmpDataStoreRecId(RecId _recordId = tmpDataStoreRecId)

{

     tmpDataStoreRecId= _recordId;

     return tmpDataStoreRecId;

}

6.  Override the prePromptModifyContract() method of the Controller class and store the passed list as the container to SRSTmpDataStore table and set the contract parm method by the table recId.

protected void prePromptModifyContract()

{

    List               myList;

    MyTmpTable        myTmpTable;

    MyReportContract     contract;

    SRSTmpDataStore     srsTmpDataStore;

    contract = this.parmReportContract().parmRdpContract() as MyReportContract;  

    if (this.parmArgs() && this.parmArgs().record())

    {

        switch (this.parmArgs().record().TableId)

        {

            case tableNum(MyTmpTable) :   

                myTmpTable = this.parmArgs().record() as MyTmpTable;

                if (this.parmArgs().parmObject())

                {

                    myList = this.parmArgs().parmObject();

                    new SRSReportRunPermission().assert();

                    ttsBegin;

                    srsTmpDataStore.Value = myList.pack();

                    srsTmpDataStore.insert();

                    ttsCommit;

                    contract.parmTmpDataStoreRecId(srsTmpDataStore.RecId);

}

break;   

            default :

                throw error(Error::wrongUseOfFunction(funcName()));

        }

    }

}

7. Override the processReport() method of the report data provide class and get the SRSTmpDataStore table RecId from the Contract class for and call the method subsequently to get it unpacked.

[SysEntryPointAttribute(false)]

public void processReport()

{

    RecId  srsTmpDataStoreRecId;

    contract = this.parmDataContract() as MyReportContract;

    srsTmpDataStoreRecId = contract.parmTmpDataStoreRecId();     

    if (srsTmpDataStoreRecId)

    {               

        this.unPackMyTmpTable(srsTmpDataStoreRecId);

    }                       

}

8.  Create a method called unPackMyTmpTable() to unpack the temporary table data and subsequently calling the method to insert data finally in the Report tmp table.

private void unPackMyTmpTable(RecId _srsTmpDataStoreRecId)
{    
    MyTmpTable     myTmpTable;
    List                    myList;
    ListEnumerator          enumerator;
    SRSTmpDataStore         srsTmpDataStore;

    new SRSReportRunPermission().assert();

    select firstOnly Value from srsTmpDataStore
        where srsTmpDataStore.RecId     == _srsTmpDataStoreRecId
           && srsTmpDataStore.CreatedBy == curuserid();

    myList = List::create(srsTmpDataStore.Value);

    enumerator = myList.getEnumerator();
    enumerator.reset();
    while (enumerator.moveNext())
    {
        myTmpTable = enumerator.current();
        this.insertIntoReportTmp(myTmpTable);
    }

    SRSTmpTblMarshaller::deleteTmpTblData(_srsTmpDataStoreRecId);
    CodeAccessPermission::revertAssert();
}

9. Create a method called insertIntoReportTmp() for inserting data into the SSRS Report tmp Table.

private void insertIntoReportTmp(Common _dataTable)

{

    MyTmpTable       myTmpTable;     

//    MyReportTmpTable myReportTmpTable; this should be declared in Class Declaration instead.

    switch (_dataTable.TableId)

    {

        case tableNum(MyTmpTable) :

        myTmpTable = _dataTable as MyTmpTable; 

            break;

        default :

            throw error(Error::wrongUseOfFunction(funcName()));

    }

    if (myTmpTable.PurchId) //this may be any field other than the RecId of the tmp data table.

    {

        // Insert the required fields here.... 

myReportTmpTable.insert();

    }

}


Comments

Popular posts from this blog

How to check if the Item is Batch / Serial Controlled through X++ Code

How to change SSRS Report Design based on Dialog value