Páginas

Como associar uma classe do Dynamics AX ao dataSet do Visual Studio

Para adicionar uma consulta para AXQuery você passa em um dicionário de objetos, o nosso range precisa ser equivalente a:
  1. select * from InventTrans where DatePhysical < _paramDate && (DateFinancial == datenull() || DateFinancial > _paramDate)
O problema está em como fazer o OR no campo DateFinancial. Além disso, como você faz entre um intervalo, você pode ter apenas um campo no dicionário o que parece só permitir ..data ou data..
Para resolver esse problema fiz o seguinte:

1- Criei uma classe na AOT chamada InventTransReport, com o seguinte método:
  1. public InventTrans returnData(str parmDate)
  2. {
  3.       InventTrans InvTr;
  4.       date parm;
  5.       ;
  6.  
  7.       parm = str2date(parmDate,123);
  8.  
  9.       select * from InvTr
  10.         where (invTr.DateFinancial < parm)
  11.            && (invTr.DateFinancial == str2date("",123)
  12.            || invTr.DatePhysical > parm);
  13.  
  14.       return InvTr;
  15. }
2 - No Visual Studio eu criei um novo projeto usando Dynamics AX Reporting Project.

3 - Depois criei um novo dataMethod no relatório com o seguinte código:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Security.Permissions;
  4. using System.Data;
  5. using Microsoft.Dynamics.Framework.Reports;
  6. public partial class Report1
  7. {
  8.     [DataMethod(), AxSessionPermission(SecurityAction.Assert)]
  9.     public static DataTable ReportInventTrans(string paramDate)
  10.     {
  11.         // Call AX to get the report data
  12.         AxaptaWrapper ax = SessionManager.GetSession();
  13.         AxaptaObjectWrapper axClass = ax.CreateAxaptaObject("InventTransReport");
  14.         AxaptaRecordWrapper axRecord = ax.CreateAxaptaRecord(axClass.Call("returnData", paramDate));
  15.        
  16.         // Prepare the DataTable structure
  17.         DataTable resTable = new DataTable();
  18.         resTable.Columns.Add("ItemID", typeof(String));
  19.         resTable.Columns.Add("DatePhysical", typeof(DateTime));
  20.         resTable.Columns.Add("DateFinancial", typeof(DateTime));
  21.         while (axRecord.Found)
  22.         {
  23.             resTable.Rows.Add(axRecord.GetField("ItemID"), axRecord.GetField("DatePhysical"), axRecord.GetField("DateFinancial"));
  24.             axRecord.Next();
  25.         }
  26.         return resTable;
  27.  
  28.     }
  29. }
4 - Depois adicionar um novo DataSet para o meu relatório e alterar a propriedade:

Data Source Type: Business Logic
Query: ReportInventTrans


5 - Depois é só passar o parâmetro para a query, nesse caso estou passando uma data, mas poderia ser apenas *.


6 - Ao executar o relatório, basta passar o parâmetro.


[]'s
Alexssander