Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ds.numberOfRowsLoaded()

547 views
Skip to first unread message

Huzaifa Gain

unread,
Jul 11, 2008, 7:48:00 PM7/11/08
to
what is the purpose of Datasource_ds.numberOfRowsLoaded() and how can i use it.

my problem to get the total number of records in the datasource.

Axel Kühn

unread,
Jul 12, 2008, 8:55:00 AM7/12/08
to
Hi,

to get the total number of records in the datasource fetched by the query
you can use SysQuery class.

ie. SysQuery::countTotal(CustTable_ds.queryRun())
CustTable_ds is the datasource of your form...
--
Sincerely yours
Axel Kühn (visit my Dynamics AX blog at: http://blog.ak-home.net)

Vanya Kashperuk Ivan at dot nospam

unread,
Jul 12, 2008, 11:46:01 AM7/12/08
to
As far as I know, the numberOfRowsLoaded method returns the number of records
that were loaded into cache, when you display a form.
I don't think you can really use it for much in your everyday work.
You would need very specific conditions to actually need to use it.
--
Kashperuk Ivan (Vanya), SDET, Inventory management, Microsoft Dynamics AX
My blog - http://kashperuk.blogspot.com
Download MorphX IT in Russian - http://www.lulu.com/content/723888

Huzaifa Gain

unread,
Jul 13, 2008, 3:36:00 AM7/13/08
to
scenario: I want to insert a record through code into the detail table when
,there are zero records in the detail table for the corresponding master
table.

Vanya Kashperuk Ivan at dot nospam

unread,
Jul 13, 2008, 3:41:00 AM7/13/08
to
Well, nobody prevents you from doing that.
But, I guess you can understand that this is kidna wrong from the
application point of view.

Just work with tables, you don't need the datasource or any of its
properties for that.

Good luck!

Huzaifa Gain

unread,
Jul 13, 2008, 3:51:00 AM7/13/08
to
but if i can get the count the data source why to query table. it will be
over head

Axel Kühn

unread,
Jul 13, 2008, 12:03:16 PM7/13/08
to
Hi,

you can just call SysQuery::countTotal to get the total count of records
fetched by the query for your detail table. Another way to get the count of
records "in" your detail datasource is to iterate over the records.

example:
void clicked()
{
CustTable tmpCustTable;
counter recordCount;
;
// 1. Solution
info(strfmt("Count of records in datasource: %1",
SysQuery::countTotal(CustTable_ds.queryRun())));

// 2. Solution
for (tmpCustTable = CustTable_ds.getFirst() ? CustTable_ds.getFirst() :
CustTable_ds.cursor();
tmpCustTable;
tmpCustTable = CustTable_ds.getNext())
{
recordCount++;
}
info(strfmt("Count of records in datasource: %1", recordCount));


}
--
Sincerely yours
Axel Kühn (visit my Dynamics AX blog at: http://blog.ak-home.net)

Vanya Kashperuk Ivan at dot nospam

unread,
Jul 13, 2008, 5:02:03 PM7/13/08
to
Actually, you will get an overhead in the exact opposite situation, by
querying the datasource.

In order for records to be "listed as records" in the datasource, they first
have to be loaded into it. In order to do this a query is executed (a number,
in fact), then the data is sent from the server to the client, and after that
there also is some time needed for processing the records in the grid control
to show them to you.

So, in any scenario, it will be much faster to query the table directly,
especially considering the caching abilities in the system (and the database)

Go with the SysQuery::countTotal method, that Axel suggested

Ricardo Pichler

unread,
Jul 14, 2008, 9:14:01 AM7/14/08
to
Hi!

Some months ago I tried to count the number of rows in a report and I don't
tried to use the Sysquery::count..... But now, how I know the command, I
tried and it fail, because I can't access the _DS like in forms, right? If
no, how I can use this to reports?

Obs.: The solution that I've used was count the rows using a while after
call the queryRun.prompt and element.prompt.

TIA,
Ricardo Pichler

Vanya Kashperuk Ivan at dot nospam

unread,
Jul 14, 2008, 9:31:04 AM7/14/08
to
SysQuery::countTotal need the QueryRun object as a parameter.
You can get the queryrun of the report like the following:

SysQuery::countTotal(element.queryRun());

if that does not work, you can do :

SysQuery::countTotal(new QueryRun(element.query()));

Hope this helps

--
Kashperuk Ivan (Vanya), SDET, Inventory management, Microsoft Dynamics AX
My blog - http://kashperuk.blogspot.com
Download MorphX IT in Russian - http://www.lulu.com/content/723888

Ricardo Pichler

unread,
Jul 14, 2008, 10:01:05 AM7/14/08
to
Kashperuk Ivan,
Thanks once more!

The "SysQuery::countTotal(element.queryRun());" work perfectly!

Regards,

Andy S. [MS]

unread,
Jul 23, 2008, 12:51:00 AM7/23/08
to
*You're going to want to use "countLoops" and not "countTotal" as I outline
below*

Note that the SysQuery class has two count methods: "countTotal" and
"countLoops". If one examines the X++ code, one will see that both call into
the "countPrim" method which does the following at its core:

while (countQueryRun.next())
{
common = countQueryRun.get(countQuery.dataSourceNo(1).table());
counter += common.RecId; // counter gets returned through countTotal
loops++; // loops gets returned through countLoops
}

A little more investigation will show that countTotal actually returns the
sum of the RecIds across the result set, while countLoops actuall returns the
number of records in the result set.

This is a very confusing API and its implementation could be much better as
well (note that it's actually bringing back an entire result set to
client/server just so it can be looped over...clearly this should be dithered
down to a select count(*)). There are currently bugs written against this and
I'm hoping its owners will fix it in 6.0
--
This posting is provided "AS IS" with no warranties, and confers no rights.

0 new messages