Visual Studio Dynamics AX 报表如何关联x++类获取数据集
Visual Studio Dynamics AX 报表中的数据集筛选器在面对一些复杂的筛选条件时,就显得力不从心了。。。
select * from InventTrans where DatePhysical < _paramDate && (DateFinancial == datenull() || DateFinancial > _paramDate)
我们可以这样做
1.创建一个类,名称InventTransReport并定义方法:
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.在Visual Studio Dynamics AX报表的项目中创建方法:
[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.Locale = CultureInfo.InvariantCulture; 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; }
最后就可以在报表中添加类型为Business Logic的数据集了