Showing posts with label Dynamics AX. Show all posts
Showing posts with label Dynamics AX. Show all posts

Sunday, March 29, 2015

Executing a Stored Procedure from AX


I am not really a fan of having external code supporting functionality within Dynamics AX, but there may come a time when for whatever reason you need to create a stored procedure and have it executed from XPP code.

server static void executeSP()
{
    Connection con = new Connection();
    Statement stmt = con.createStatement();
    ResultSet r;
    str sql;
    SqlStatementExecutePermission perm;
    ;
    sql = strfmt('EXEC [insertdaxjob]');
    perm = new SqlStatementExecutePermission(sql);
    perm.assert();
    try
    {
        stmt.executeUpdate(sql);
    }
    catch (exception::Error)
    {
        print "An error occured in the query.";
        pause;
    }
    CodeAccessPermission::revertAssert();
}

Debugging a Dynamics AX2012 SSRS RDP Report


I haven't put my finger on it yet, but there are times when I am unable to debug an SSRS RDP Report.  I add my breakpoint but during code execution, the system just won't break when it should.  I believe this is related to how the classes are extended.

While faced with this delima, I did some research on the internet and found an article which shows how to create a job for debugging purposes.  Please follow this link for the original reference: Test Report Data Provider in AX2012.

The following is a simple job to invoke an SSRS RDP report.  It doesn't actually print the report, but it does do the meat of the processing so you can debug your RDP code.  Substitute your RDP class and Contract information as required.

static void Job3(Args _args){
TmpABC tempTable;
InventABCDP dataProvider = new InventABCDP();
InventABCContract contract = new InventABCContract();
contract.parmABCModel(ABCModel::Link);
contract.parmCategoryA(10);
contract.parmCategoryC(20);
contract.parmCategoryB(70);
contract.parmInterest(2.5);

dataProvider.parmDataContract(contract);
dataProvider.processReport();
tempTable = dataProvider.getTmpABC();

while
 select tempTable
{
info(tempTable.ItemName);
}
}