Wednesday, March 23, 2016

SSRS - one or more projects in the solution were not loaded correctly

Hi, even though this error is a simple and actually found at the beginning only when start report developing however I think it would be ok as well if I logged it in the forum.

 --- Issue ---
In the multiple AOS environments, we create a SSRS report in Visual Studio and then save and add it back to AOT. Next day, we open AOT and try to edit that VS Studio project. But found the error like this.
one or more projects in the solution were not loaded correctly.
C:\Users\..\Microsoft Dynamics AX\Dynamics AX Model Projects\ShReleaseProductReport\ShReleaseProductReport.dynamicsproj : error : Unable to connect to the AOS specified in the Microsoft Dynamics AX Client Configuration. The configuration could be missing, invalid, or the AOS is not running. To connect to the AOS, check the network connection between the client and the AOS, verify that a valid configuration exists, and that the AOS service is running on the server.

--- Resolution ---
- Open AX 2012 Client configuration
- At 'Set Configuration Store' --> Load the correct client axc file
- It will show as follows.

Friday, March 18, 2016

SQL Server: Using SqlCmd to export table (including header) to CSV

SQLCMD is a tool which can export dynamics AX 2012 table to CSV easily. Let's see.

sqlcmd  -E -Q "select * from AX2012_Train.dbo.BANKPARAMETERS" -o "e:\test\test.csv" -s","
Until the next post! :-)

SQL Server: Using BCP to export table (including header) to CSV

If we have to export a table to CSV file. There is a simple way to do this by BCP. 

BCP "DECLARE @colnames VARCHAR(max);SELECT @colnames = COALESCE(@colnames + ',', '') + column_name 
from AX2012_Train.INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='BANKPARAMETERS'; 
select @colnames;" queryout e:\test\HeadersOnly.csv -c -T 

BCP AX2012_Train.dbo.BANKPARAMETERS out e:\test\TableDataWithoutHeaders.csv -c -t, -T 

copy /b e:\test\HeadersOnly.csv+e:\test\TableDataWithoutHeaders.csv e:\test\TableData.csv

del e:\test\HeadersOnly.csv
del e:\test\TableDataWithoutHeaders.csv

However this way isn't a best solution to extract table in Dynamics AX 2012 because the column of AX table doesn't sort in the ascending order. (Some field such as RecId, DataAreaId will be put at the last)  But I'm sure this code will be useful in the general case.

SQL Server: Display table name

Hi, today I will show the simple query which run on Query editior on MS SQL Server Management studio. It displays the table names in Dynamics AX database.

select *
from INFORMATION_SCHEMA.TABLES
where TABLE_NAME like '%parameters%' and
    TABLE_NAME not like '%_BE' and
   TABLE_NAME not like '%_BR' and
   TABLE_NAME not like '%_CN' and
   TABLE_NAME not like '%_DE' and
   TABLE_NAME not like '%_NL' and
   TABLE_NAME not like '%_RU' and
   TABLE_NAME not like '%_UK';


Tuesday, March 15, 2016

X++ Deal with a table buffer as a variable (part2)

Refer to MSDN page Table as data type

We can also write or refer to a field as a variable like as below code.


public void printCust()
{
    int i, n, k;
    CustTable custTable;
    DictTable dictTable;
    ;
 
    dictTable = new DictTable(custTable.TableId);
    n = dictTable.fieldCnt();
 
    print "Number of fields in table: ", n;
    for(i=1; i<=n; i++)
    {
        k = dictTable.fieldCnt2Id(i);
        print "The ", dictTable.fieldName(k), 
            " field with Id=",k, " contains '", 
            custTable.(k), "'";
        pause;
    }
}



X++ Deal with a table buffer as a variable

Sometimes we got some requests which need to write the same select statement or query for many tables. This below simple code might be useful.


static void Job16(Args _args)
{
    SysDictTable    dictTable;
    Common          common;    
    str             tblName;
    ;
    
    tblName     = 'InventTable';
    dictTable   = SysDictTable::newName(tblName);
    common      = dictTable.makeRecord();

    select count(RecId) from common;
    info(strFmt('All records of %1 are %2',tblName,common.RecId));    
}


Thanks, Martin DrĂ¡b from this post String value as tableName in Select Statement

Tuesday, March 8, 2016

X++ Useful shortcut & hot keys

Here, the shortcut & hot keys which might be useful. Will try to update when find some more interesting.



Mark comment                         Ctrl + e + c
Unmark comment                     Ctrl + e + u

Monday, March 7, 2016

X++ Get stock on hand on an item

Refer to AX2012: X++ code to get on hand on an item Priyanka Agarwal gave an excellent clarification about getting stock on hand by given item, and dimension.

Below example shows the simple code to retrieve stock on hand on an item, without given any inventory dimensions.

    
static void Job12(Args _args)
{
    InventTable inventTable;
    ;
    
    while
    select firstOnly10 ItemId
        from inventTable
        index ItemIdx
    {
        info(inventTable.ItemId);
        info(strFmt('%1',InventOnhand::newItemId(inventTable.ItemId).availPhysical()));    
    }
}

X++ Consideration for Change Company Using

Refer to ChangeCompany and table buffers

Be careful when using 'changeCompany'. We have to clear the table buffer unless the company will not be changed as we expected. This happens when we use the same name of table buffer.

See below example.

    changeCompany('A')
    {
        while
        select  ModelGroupId
        from    inventModelGroup
        index   GroupIdx
        {
         ...
         ...
        }
    }
    changeCompany('B')
    {
        inventModelGroup = null;        //Need this statement to clear table buffer
        while
        select  ModelGroupId
        from    inventModelGroup
        index   GroupIdx
        {
         ...
         ...
        }
    }

X++ Create a simple CSV file (part 2)

Hi I found another way to write CSV in a job which is simpler than the previous one I posted.

Refer to Santosh Kumar Singh's blog

Let say I re-post Santosh Kumar Singh's code again with a bit layout adjust. Thanks him for a nice code.


CommaTextIo file;
container line;
CustTable custTable;
#define.filename(@'C:\Test\TestFile.csv')
#File
;

file = new CommaTextIo(#filename, #io_write);
if (!file || file.status() != IO_Status::Ok)
{
   throw error("File cannot be opened.");
}

while select AccountNum, Name from custTable
{
   line = [custTable.Name,
           custTable.Name];
   file.writeExp(line);
}

info(strFmt("File %1 created in specified folder.", #filename));
}