How to retrieve data with offset and limit using webservice request?

792 Views Asked by At

I am trying to build an AX service to retrieve data from InventTable in Microsoft Dynamics AX 2009. With reference to https://community.dynamics.com/ax/f/33/t/70476.aspx ,I tried to execute a code in AOT Job for retrieving data with modifieddate="2/7/2013" The code sample is as below:

    static void SelectQueryTest(Args _args)
    {
       Query q = new Query();
    QueryRun qr;
    QueryBuildDataSource qbds;
    int64 countItem;
    InventTable inventTable;
    Fromdate FromDate = 2\7\2013;


    ;

    qbds = q.addDataSource(tableNum(InventTable));
    qbds.addRange(fieldNum(InventTable, modifiedDateTime)).value(date2StrUsr(FromDate ));
    qr = new QueryRun(q);
    countItem =SysQuery::countTotal(qr);
   if(countItem>0)
   {

     while(qr.next())
    {

        inventTable = qr.get(tableNum(inventTable));
        info(strfmt("Item Name: %1", inventTable.ItemName));
    }
   }
   else
   {
     info("No records found");
   }

    }

Can any one suggest me how to write a code which retrieves data using offset and limit that is taken from a webservice request.

2

There are 2 best solutions below

0
On BEST ANSWER

limit and offset are not available in x++ when querying AX.

In my opinion you have 2 options to acheive the same goal.

  1. Order your result set by recId, store the recId, and the use where recId > yourRecId for your offset. You would also need to count the records manually using something like while select.

  2. Use x++ to query the SQL database directly, in which case you should be able to use any SQL supported by the server

1
On

You will most likely do not need to make a service yourself, as there are standard ways to do it.

Take a look on the answers here: Fetching data from dynamics ax 2009 using Ax webservices and C#

Also take a look on this screencast.