我使用以下代码片段从c#中提取Dynamics AX 2009中的数据。除了基础字段类型是维度的情况之外,这种方法很好。我希望能够在返回时“展平”数组类型,但无法看到任何方法。任何人的想法?
axRecord = ax.CreateAxaptaRecord(tableName);
axRecord.ExecuteStmt(strQuery);
// Loop through the set of retrieved records.
using (StreamWriter sw = File.CreateText(path))
{
AxaptaObject axDictTable = ax.CreateAxaptaObject("SysDictTable",axRecord.get_Field("tableid"));
outputRow = null;
List<int> ids = new List<int>();
for (int i = 1; i <= (int)axDictTable.Call("fieldCnt"); i++)
{
AxaptaObject axDictField = ax.CreateAxaptaObject("DictField", axRecord.get_Field("tableid"), axDictTable.Call("fieldCnt2ID", i));
outputRow += ((string)axDictField.Call("Name")) + ",";
ids.Add((int)axDictTable.Call("fieldCnt2ID", i));
}
sw.WriteLine(outputRow);
while (axRecord.Found)
{
outputRow = null;
foreach(int i in ids)
outputRow += axRecord.get_Field(i).ToString().Replace(",", "") + ",";
sw.WriteLine(outputRow);
axRecord.Next();
}
}
答案 0 :(得分:1)
您可以通过(X ++代码)检查该字段是否为数组,然后按照您的方式“展平”它:
currentTable = new SysDictTable(tablenum(ledgerJournalTable));
for(i = 0;i<=currentTable.fieldCntWithoutSys();i++)
{
currentField = new SysDictField(currentTable.id(), currentTable.fieldCnt2Id(i));
if(currentField.arraySize() > 1)
{
//your code
}
}
答案 1 :(得分:0)
您可以随时安全地投射对象:
var o = ax.CreateAxaptaObject() as AxaptaObject;
if(o != null)
{
...code
}