AX 2012 how to set args record datasource in X++

Muhammad Anas Khan picture Muhammad Anas Khan · Jan 30, 2014 · Viewed 24.1k times · Source

Can anyone tell me what should I do in X++ to get a NOT null value from args.record().datasource() method after executing the following statements:

PurchTable    purchTable;

args.record(purchTable);

if(args.record().datasource())  //this condition fails because of null value
{
    //I have to reach here
}

I know that the same code works fine when it is called from Form but my scenario is that I have to execute this code from within X++. Please help!

Answer

Geoffrey DELMEE picture Geoffrey DELMEE · Jan 31, 2014

args.record().datasource() will retrieve a form datasource. Here, you are using a table buffer only. That's why you don't have anything.

If you want to retrieve the table buffer, you might go this way:

PurchTable purchTable;
PurchTable argPurchTable;

select firstOnly purchTable;
args.record(purchTable);

if (args.record() && args.dataset() == tableNum(PurchTable))
{
    argPurchTable = args.record();
    //do something
}

Regards,

Geoffrey