The metadata service allows external consumers to obtain information about the AOT objects within Microsoft Dynamics AX, such as tables, queries, forms, and so on. When we take a look at the operations available in the service, we can see the following two types of operations:
GetQueryNames
operation, which returns a list of query names available in the systemGetTableMetaDataByName
operation, which takes an array of table names and returns all of the metadata information available for these tablesYou can find detailed class diagrams on MSDN describing the metadata classes at http://msdn.microsoft.com/en-us/library/gg845212.
Let's start by taking a look at the code that is executed when the form loads.
To fill the combobox, we need to use the GetQueryNames
operation on the metadata service and filter the results to show only the queries that start with CVR
. You can use the following code to do this:
private void MainForm_Load(object sender, EventArgs e) { // Create a service client AxMetadataServiceClient client = new AxMetadataServiceClient(); // Get queries from Ax that start with CVR IList<string> queryNames = client.GetQueryNames() .Where(queryItem => queryItem.StartsWith("CVR")).ToList(); // Set the results as the combobox's data source cboAxQueryName.DataSource = queryNames; }
First, the service client is created:
AxMetadataServiceClient client = new AxMetadataServiceClient();
Then, the following line invokes the operation to retrieve all of the query names. We apply a lambda expression to the IList
object to filter out the queries that start with CVR
using the following line:
IList<string> queryNames = client.GetQueryNames() .Where(queryItem => queryItem.StartsWith("CVR")).ToList();
Lastly, we just take the result and set it as the data source of the combobox using the following line of code:
cboAxQueryName.DataSource = queryNames;
When running your application, you should see the following result:
3.138.34.226