26.05.2016, 18:11 | #1 |
Участник
|
stoneridgesoftware: How to use a View to Simplify Working with Query Classes in Dynamics AX
Источник: https://stoneridgesoftware.com/how-t...n-dynamics-ax/
============== Have you ever used a View to simplify working with Query classes in Dynamics AX? I have worked on a couple projects where my lookups were not working quite like I wanted them to when working with the Query classes. The problems specifically happened when I wanted to see data from a child table that was two, three or four levels deep. The lookup wouldn’t run or the data coming back into the lookup form would say ‘Unknown’. I thought to myself, it would be nice if the data I wanted to see was in one table and I would not need to do any joins using the Query classes. This is when I realized that using a custom View created in the AOT would be handy. Let’s say I wanted to see data related to Project Contracts and their Customers that are associated with Projects in my lookup. (Physical table and field names in parentheses): Project ID (ProjTable.ProjId) Project Name (ProjTable.Name) Project Contract ID (ProjTable.ProjInvoiceProjId) Project Contract Name (ProjInvoiceTable.Description) Customer ID (ProjTable.CustAccount) Customer Name (DirpartyTable.Name) The customer name lives in DirPartyTable so this will require joining three tables to get to it: ProjTable.CustAccount -> CustTable.AccountNum -> CustTable.Party -> DirPartyTable.RecId To create the view in the AOT, you can choose a table based one or a query based one. If you want a query based one, then you create the query in the AOT first and then select it using the Properties window of the view object. This is an example of the CustBankAccountCrossCompanyView that is query based: I used a table based query for this solution. The ProjTable will be the parent table and will join the other three tables I listed above. The view looks like this: Now that my view is defined in the AOT, I can now test it in a job or a custom lookup with X++. The following is a job that displays the data for a certain Customer number: X++: static void ProjectContractInfoViewTest(Args _args) { ProjectContractInfoView projectContractInfoView; Query query; QueryRun qRun; QueryBuildDataSource qBDSource; QueryBuildRange querybuildRange; CustAccount customerID; int i = 0; customerID = "1010-1010123"; query = new Query(); qBDSource = query.addDataSource(tablenum(ProjectContractInfoView)); querybuildRange = qBDSource.addRange(fieldnum(ProjectContractInfoView, CustAccount)); querybuildRange.value(customerID); qRun = new QueryRun(query); while (qRun.next()) { projectContractInfoView = qRun.get(tablenum(ProjectContractInfoView)); info("ProjId: " + projectContractInfoView.ProjId + " Contract Id: " + projectContractInfoView.ProjInvoiceProjId + " Contract Desc: " + projectContractInfoView.ProjContractDesc + " Customer Name: " + projectContractInfoView.CustomerName); i++; } info(int2str(i) + " Records found using range on CustAccount."); } Here would be a similar example of the job code in a method that would be used in a lookup filtering on a Customer number: X++: public static void lookupProjectCustomerId(FormControl _formControl, CustAccount _customerID) { SysTableLookup sysTableLookup = SysTableLookup::newParameters(tablenum(ProjectContractInfoView), _formControl); Query query = new Query(); QueryBuildDataSource qBDSource; QueryBuildRange querybuildRange; qBDSource = query.addDataSource(tableNum(ProjectContractInfoView)); // Filter on the Customer ID if (_customerID) { querybuildRange = qBDSource.addRange(fieldnum(ProjectContractInfoView, CustAccount)); querybuildRange.value(_customerID); } sysTableLookup.addLookupfield(fieldnum(ProjectContractInfoView, ProjId)); sysTableLookup.addLookupfield(fieldnum(ProjectContractInfoView, ProjInvoiceProjId)); sysTableLookup.addLookupfield(fieldnum(ProjectContractInfoView, ProjContractDesc)); sysTableLookup.addLookupfield(fieldnum(ProjectContractInfoView, CustomerName)); sysTableLookup.addLookupfield(fieldnum(ProjectContractInfoView, ProjectName)); sysTableLookup.parmQuery(query); sysTableLookup.performFormLookup(); } Источник: https://stoneridgesoftware.com/how-t...n-dynamics-ax/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. Последний раз редактировалось mazzy; 26.05.2016 в 18:55. |
|
|
Опции темы | Поиск в этой теме |
Опции просмотра | |
|