Search code examples
c#axaptaax

Using Query datatype in C#


I have a piece of code which returns a Sales Order from AX. In that record im using the querySalesLine method but I'm not sure where I go from there to get all the lines attached to the order below is my code:

AxaptaRecord OrderRecord = (AxaptaRecord)ax.CallStaticClassMethod("OnlineOrder", "getSalesOrder", salesRef);

if(OrderRecord.Found)
{
     AxaptaObject Lines = (AxaptaObject)OrderRecord.Call("querySalesLine");
}

How would I then use this Lines object to retrieve all of the items attached to this order? I know that the querySalesLine returns a Query object but not sure what to do next.


Solution

  • You should create a QueryRun object, then use that object to read the lines.

    var qLines = (AxaptaObject)OrderRecord.Call("querySalesLine");
    var qrLines = ax.CreateAxaptaObject("QueryRun", qLines);
    

    To read the lines use this answer.

    The Query is a static description of the query.

    The QueryRun uses the query to find the records.