Para adicionar uma consulta para AXQuery você passa em um dicionário de objetos, o nosso range precisa ser equivalente a:
- 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:
- public InventTrans returnData(str parmDate)
- {
- InventTrans InvTr;
- date parm;
- ;
- parm = str2date(parmDate,123);
- select * from InvTr
- where (invTr.DateFinancial < parm)
- && (invTr.DateFinancial == str2date("",123)
- || invTr.DatePhysical > parm);
- return InvTr;
- }
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:
- using System;
- using System.Collections.Generic;
- using System.Security.Permissions;
- using System.Data;
- using Microsoft.Dynamics.Framework.Reports;
- public partial class Report1
- {
- [DataMethod(), AxSessionPermission(SecurityAction.Assert)]
- public static DataTable ReportInventTrans(string paramDate)
- {
- // Call AX to get the report data
- AxaptaWrapper ax = SessionManager.GetSession();
- AxaptaObjectWrapper axClass = ax.CreateAxaptaObject("InventTransReport");
- AxaptaRecordWrapper axRecord = ax.CreateAxaptaRecord(axClass.Call("returnData", paramDate));
- // Prepare the DataTable structure
- DataTable resTable = new DataTable();
- resTable.Columns.Add("ItemID", typeof(String));
- resTable.Columns.Add("DatePhysical", typeof(DateTime));
- resTable.Columns.Add("DateFinancial", typeof(DateTime));
- while (axRecord.Found)
- {
- resTable.Rows.Add(axRecord.GetField("ItemID"), axRecord.GetField("DatePhysical"), axRecord.GetField("DateFinancial"));
- axRecord.Next();
- }
- return resTable;
- }
- }
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