0

我正在使用以下代码片段从 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();
     }
}
4

2 回答 2

1

You could check if the field is an array by (X++ code), and then work this out your way to "flatten" it:

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
    }
}
于 2010-12-30T13:38:00.733 回答
0

您始终可以像这样安全地投射对象:

var o = ax.CreateAxaptaObject() as AxaptaObject;
if(o != null)
{
...code
}
于 2010-12-31T13:33:15.070 回答