Monday 6 February 2012

Get all dimensions available in AX for any given Environment


How to get all dimensions available in any environment , the below job will help us
static void getAllDimension(Args _args)
{
    Counter         idx;
    Dimension       dimension;
    DimensionCode   dimensionCode;
    str             name;
    ;
    for (idx = 1; idx <= dimof(dimension); idx++)
    {
        dimensionCode = Dimensions::arrayIdx2Code(idx);
        name = enum2str(dimensionCode);
        // if (name == 'B') ...
        info(strfmt("%1: %2", idx, name));
    }
}

Request for the permission of type 'SqlStatementExecutePermission' failed.

While running one Job , where I was trying to execute one SQL statement in AX, I got the below stack trace :


Request for the permission of type 'SqlStatementExecutePermission' failed.
(S)\Classes\SqlStatementExecutePermission\demand
(S)\Classes\Statement\executeQuery
(C)\Jobs\test - line 21


So what is the solution for this , Very simple , we need to run this job on Server , So now how to do it :
here is solution , create a menu item of type action, give the object type as Job ,and object name , and set the property Run on as" Server ".

There you go , Problem solved  :) 

Get Database size using X++

How to get size of Database being used by AX ,below job can help you :



static void GetDBSize(Args _args)
{
LoginProperty loginProp;
ODBCConnection conn;
Resultset resultSet, resultSetCount;
Statement statement1, statement2;
str test;
real s;
SysSQLSystemInfo   systemInfo =  SysSQLSystemInfo::construct();

;

 test = strfmt( "SELECT size FROM sys.master_files where name = '%1'",systemInfo.getloginDatabase()  );
loginProp = new LoginProperty();

loginProp.setServer(systemInfo.getLoginServer());
loginProp.setDatabase(systemInfo.getloginDatabase());

conn = new ODBCConnection(loginProp);

statement1 = conn.createStatement();
resultSet = statement1.executeQuery(test);

while (resultSet.next())
{
s = str2int(resultSet.getString(1));
s = s*8 /1024;
info(strfmt("%1  MB",s));
}
}