Monday, September 11, 2017

Get SSAS cube related data in AX 2012

//Get cube related data in AX 2012

//Prerequisite
//Add new references node in AOT Microsoft.AnalysisServices.AdomdClient

static void SSLSSASCubeData(Args _args)
{
    str                                cubeConnectionString, cubeQuery, value;
    int                                i, rowCount;
    
    System.Data.DataTable              dataTable;
    System.Data.DataRowCollection      collection;
    System.Data.DataRow                row; 
    System.Object                      object;
    
    Microsoft.AnalysisServices.AdomdClient.AdomdConnection      Conn;
    Microsoft.AnalysisServices.AdomdClient.AdomdDataAdapter     dataAdapter;
    
    cubeConnectionString = 'Data Source=SSAS_SERVER;Catalog=SalesCube';
    cubeQuery = 'Select SalesNum from SalesCube';
    
    dataTable = new System.Data.DataTable();
    
    Conn = new Microsoft.AnalysisServices.AdomdClient.AdomdConnection(cubeConnectionString);
    dataAdapter = new Microsoft.AnalysisServices.AdomdClient.AdomdDataAdapter(cubeQuery, Conn);
    dataAdapter.Fill(dataTable);
    
    collection = dataTable.get_Rows(); 
    rowCount = collection.get_Count();    
    
    for (i = 0; i < rowCount; i++) 
    { 
        row = collection.get_Item(i); 
        object = row.get_Item(0);
        value = object.ToString();
        
        info(strFmt('%1. %2', i+1, value));
    } 
    
    Conn.Close();
}

No comments:

Post a Comment

Convert Call stack to readable format in D365FO X++

//Input --container _xppCallStack = xSession::xppCallStack();  Public static str POL_formatXppCallStack(container _xppCallStack, int _skipFr...