Microsoft Dynamics AX 2012 comes with a pre-installed, all important, AIF query service. Query service can be used to fetch ad hoc data from AX2012 without creating a service. There are three types of queries that you can run through a query service but I am discussing only the first two options here:

  • Static query: use this if you require re-using the fetch query. This mod requires you to create the AOT query first.
  • User defined query: use this mod if you don’t want to create the AOT query. In this mod, QueryMetaData object is been used to build the query at runtime.

In the below mentioned code snippet, I am trying to fetch all the records from the HcmWorker table through the user defined query. In order to run this snippet, please make sure that AIF services are deployed and you are able to access the query service. Typical URI for the query service WSDL is:


The code snippet to fetch all the records from HcmWorker is:

QueryServiceClient client = new QueryServiceClient();

QueryMetadata queryMetaData = new QueryMetadata();

queryMetaData.DataSources = new QueryDataSourceMetadata[] {

new QueryDataSourceMetadata() { DynamicFieldList=true, Table=”HcmWorker”,  Name=”HcmWorker”,  Enabled=true}


Paging paging = null;


DataSet ds = client.ExecuteQuery(queryMetaData, ref paging);

foreach (DataRow dr in ds.Tables[0].Rows)






Happy DAXing 🙂


Leave a Reply

Recent Comments