Category Archives: Dynamics AX 2012 R2

How to get SalesLine record from ReqTrans table using X++ AX 2012

Add these two methods to the ReqTrans table

public SalesLine getSalesLine(ReqTrans _reqTrans)
{
    ReqTrans        reqTrans_Settle,reqTrans_next;
    SalesLine       salesLine;
    ;
    reqTrans_Settle = _reqTrans.getSettleTrans();
    do
    {
        select reqTrans_next
            where reqTrans_next.RefId == reqTrans_Settle.RefId
               && reqTrans_next.Direction == InventDirection::Receipt;
        if (!reqTrans_next)
        {
            break;
        }
        reqTrans_Settle = reqTrans_next.getSettleTrans();
    }
    while(reqTrans_next);
 
    if(reqTrans_Settle.RefType == ReqRefType::Sales)
    {
        salesLine = SalesLine::findInventTransId(InventTransOrigin::find(reqTrans_Settle.InventTransOrigin).InventTransId);
    }
 
    return salesLine;
}
 
private ReqTrans getSettleTrans()
{
    ReqTrans    reqTrans_Settle;
    ReqTransCov reqTransCov;
    ;
 
    switch(this.Direction)
    {
        case InventDirection::Issue:
                select reqTransCov
                    where reqTransCov.IssueRecId == this.RecId;
 
                reqTrans_Settle = reqTrans::findRecId(reqTransCov.ReceiptRecId);
            break;
 
        case InventDirection::Receipt:
                select reqTransCov
                    where reqTransCov.ReceiptRecId == this.RecId;
 
                reqTrans_Settle = reqTrans::findRecId(reqTransCov.IssueRecId);
            break;
 
    }
 
    return reqTrans_Settle;
}

AX2012 SSRS Unable to log on to Microsoft Dynamics AX

When you run any Report and the system returns the error:

Unable to log on to Microsoft Dynamics AX

The solution, that works for me, is to run the Reporting Services with the same user used for runing the AOS

AX2012 R2: Failed to create a session

I retrive in AX2012 R2 the foolowing error when I sync the DB or when I try to load a queque of batch jobs:

Failed to create a session; confirm that the user has the proper privileges to log on to Microsoft Dynamics

A closer look into this learned that this is linked to the new partitions feature.

It seems the UserInfo table is not correctly updated and the partition administrator is not updated correctly when you restore an existing DB or the Demo database.
To fix this, you can do the following.

Stop the AOS
Restore the database again
Start the AOS
Start a client and complete the partition initialiasation checklist
Close the client and execute the script below on the SQL database
Restart the client and reimport your license (if you were restoring the Microsoft demo data, the demo license is back in there)
Then compile / generate CIL / DB sync and you should be on track again!
The script for updating the UserInfo inforation is as follows:

How to create a custom Dialog with AX 2012

How to find by X++ code On Hand Stock for an Item

The example below show how to find On Hand Stock quantity for and Item

How to use the Carriage Return on AX2012 & SSRS Reports

Below you can find an example to use the Carriage Return on a SSRS Report, in order to show the data in multiples lines

Error when generating CIL on AX 2012

When you run a Full CIL or an Incremental CIL and the system returns this error:

CIL generation: The given key was not present in the dictionary

You must navigate this path: C:Program FilesMicrosoft Dynamics AX60Server<AOS ISTANCE NAME>binXppIL

and open the file: Dynamics.Ax.Application.dll.log

here you can see error like this:

Finished pass 1 at 28/10/2013 09:12:55
Error when loading the method. Type: TaxSalesShippingBill_IN, Method: new
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary

Now you must correct all exceptions and recompile the objects

Executing SQL statements from X++

Example #1: Retrieve data:

Example #2: Edit data (delete):

How to get day month year from date in AX X++

Get field label in X++

With this little example we can get the Label assigned to Field Table