Discussion:
String to table
(too old to reply)
Morten S.
2010-08-24 08:44:03 UTC
Permalink
Hi everybody,

I have a table name as a string (not a buffer) and I want to know if that
table has records or not.

I don't want to use the recordCount()-method like this:

dictTable = new SysdictTable(tablename2id("custTable"));
recordCount = dictTable.recordCount();

because the recordCount takes a long time.

Can someone please tell me how to make a "select firstonly" just to find out
if there are any records in the table I have in my string?
Klaas Deforche
2010-08-24 09:25:03 UTC
Permalink
Hi,

You could try doing a 'select firstonly' using query and queryrun.
Use the tablename2id() method to get the tableid.

See this sample job:
static void klforselectfirstonlyqueryrun(Args _args)
{
Query query;
TableId tableId;
QueryRun queryRun;
boolean hasRecords = false;
;

tableId = tablename2id("CustTable");

query = new Query();
query.addDataSource(tableId);
query.dataSourceTable(tableId).firstOnly(true);

queryRun = new QueryRun(query);

while(queryRun.next())
{
hasRecords = true;
}

if(hasRecords)
{
info("Table has a least one record");
}
else
{
info("Table has no records");
}
}

Hope this helps!
Best regards,
Klaas Deforche
----------------
http://www.artofcreation.be
Post by Morten S.
Hi everybody,
I have a table name as a string (not a buffer) and I want to know if that
table has records or not.
dictTable = new SysdictTable(tablename2id("custTable"));
recordCount = dictTable.recordCount();
because the recordCount takes a long time.
Can someone please tell me how to make a "select firstonly" just to find out
if there are any records in the table I have in my string?
Morten S.
2010-08-24 10:09:03 UTC
Permalink
That works fine. Thank you very much!
unknown
2010-08-24 19:29:21 UTC
Permalink
Post by Morten S.
Hi everybody,
I have a table name as a string (not a buffer) and I want to know if that
table has records or not.
dictTable = new SysdictTable(tablename2id("custTable"));
recordCount = dictTable.recordCount();
because the recordCount takes a long time.
Can someone please tell me how to make a "select firstonly" just to find out
if there are any records in the table I have in my string?
Hi Morten,

You can also do:
DictTable dictTable = new SysdictTable(tablename2id("custTable"));
Common common= dictTable.makeRecord();

select firstOnly common;
if(common)
{
//there's at least one record on the table
}

Regards
Michal
--
http://AXImprove.co.uk | Solutions for AX performance and data storage
management.
Loading...