Tuesday 10 February 2015

Create a Query in Axapta

Query is the most widely used AOT object in Dynamics AX customization and development. After creation it can be used as a data source in the following AOT objects: -

  • Forms
  • DataSets
  • Reports
  • Views
To create a query, follow the following steps: -

  1. In AOT select Queries node, right click and select "New Query" command. This creates a new query sub-node under the Queries node.
  2. By default "Query1" is the name of your new query. To change its name, go to properties window and change the value in the "Name" property. OR press F2 when query is selected, now you can directly write its name on the node. For example write its name as "AxdLedgerJournal".
  3. Now you have to specify its data source. Expand this query's node by clicking on "plus" sign. Now right click on "Data Sources" node and select "New Data Source" command. This adds a new data source node. In properties window select the table name in the "Table" property. For example, select "LedgerJournalTable" table. (You can also add a new data source by dragging the table from AOT's Data Distionary>Tables collection and drop it on "Data Sources" sub-node of your query.)
  4. Now select its fields. Expand newly added data source node and select "Fields" sub-node.In the properties window, select "Yes" for the property "Dynamic". In this way it adds all the fields of the selected data source in the query. 
  5. Now if you want to add one or more child data sources, then select the "Data Sources" node under your existing data source (in this case data source name is "LedgerJournalTable") right click and select "New Data Source". Change its table property to select a table, for example "LedgerJournalTrans".
  6. Add its fields by setting its dynamic property to "Yes".
  7. Now to specify this child data source relation with its parent data source, select "Relations" node, right click and select "New Relation" command. This adds a new relationship node under"Relations" node.
  8. By default it selects the most appropriate relationship is created between 2 data sources. For example in our case "JournalNum" is selected in both data sources. Click on this new relation node and check its properties. In the "Field" property, list of fields shown from the parent data source.And in the "RelatedField" property, list of fields shown from the child data source.
Now your query is ready to use it with other AOT objects. Before using "Compile" this query by selecting the "Compile" command when right click on newly created query (AxdLedgerJournal). Here is the screenshot of this example.




No comments:

Post a Comment