Reputation: 53
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!
Upvotes: 3
Views: 35763
Reputation: 1
Form pseudoForm;
FormBuildDesign formBuildDesign;
FormRun formRun;
FormBuildDataSource formBuildDataSource;
FormDataSource formDataSource;
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange queryBuildRange;
Args args = new Args();
pseudoForm = new Form();
formBuildDataSource = pseudoForm.addDataSource("inventTable");
formBuildDesign = pseudoForm.addDesign("Design");
args.object(pseudoForm);
formRun = new FormRun(args);
formRun.init();
formDataSource = formRun.dataSource(1);
formDataSource.query().dataSourceNo(1)
.addRange(fieldNum(InventTable,Itemid)).value("000.0000.00A");
formDataSource.executeQuery();
formDataSource.getFirst();
formDataSource=formDataSource.getFirst().dataSource();
info(formDataSource.name());
args.record(formDataSource.getFirst());
EcoResProductValidatonServiceProxy::main(args);
Upvotes: 0
Reputation: 782
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
Upvotes: 4