How to create the Table Object Dynamicaly ??

Hello to all ,

I am selecting the table dyanamicaly .So In the bellow code in need to create the Table object dynamicaly to catch the queryrun data.

Query q;

QueryRun qr;

QueryBuildDataSource qbd;

QueryBuildRange qbr;

CustTable Cust, cust1;

vendtable vend ;

DictTable dt;

str tabName ;

;

q = new Query();

qbd = q.addDataSource(ChkNumberSeq.convTableId); // here m using the table ID which is dynamic .

qr = new QueryRun(q);

if(qr.prompt())

{

while (qr.next())

{

if(qr.changed(ChkNumberSeq.convTableId))

{

cust = qr.get(ChkNumberSeq.convTableId); // i am using CustTable object to catch the data .i need to create table object dynamicaly to catch the data or else can i get the data from querrun itself.

info(strfmt(“custable.accNum: %1”, cust.AccountNum ));

}

}

}

Please help .

Thanks in adavnce.

regards

Ganesh Sahane

Can you please elaborate what you are trying to achieve with this?

Hi Kranti ,

i am developing one form in which i have given one lookup from where user will select the table.Now i hav the table id of that table .As i given in a code m applaying some range on it.So now m getting the data from queryrun .My problem is how i can catch that data ?

Regards

Ganesh Sahane

You need to declare the variable as Common - then you can assign any table to it.

Of course, you can’t access fields by names if you don’t know what table it is, i.e. you don’t know what fields are available.

HI Martin

That’s what m thninking . IF i declare common table varible i can use it as a selected table object.But how i sappose to declare a common table variable ? working on Ax03 .

Regards

Ganesh Sahane

It’s actually called “Common”. [:)]

Common t1;
...
t1 = qr.get(ChkNumberSeq.convTableId); 

Hey Martin ,

Thats cool … [:)] . Now how can i access the fields ??

Regards

Ganesh Sahane

Martin

Actually i can use caption() of common class to get the values of titlefield1and titlefield2 .I am trying to find any other way lest c .

regards

Ganesh Sahane

You can use reflection to get information about the actual table and access fields in X++ via their IDs. The following example shows values of all fields in a given table:

Common t1 = InventParameters::find();
SysDictTable dictTable = new SysDictTable(t1.TableId);
FieldId fieldId;
;
fieldId = dictTable.fieldNext(0);

while (fieldId)
{
    print t1.(fieldId);
    fieldId = dictTable.fieldNext(fieldId);
}
pause;

You can modify it in many ways, depending on what you need and what information you have about the tables. For example, you may get fields from a particular field group, find fields with specific data types and so on.

Dear Martin ,

Thts really helpful. Many thanks .

regards

Ganesh Sahane