How can I export an array from Dynamics AX 2009 via c#?

Posted by Steve Homer on Stack Overflow See other posts from Stack Overflow or by Steve Homer
Published on 2010-12-30T11:09:24Z Indexed on 2010/12/30 13:54 UTC
Read the original article Hit count: 330

I'm pulling data from Dynamics AX 2009 from c# using the following code snippet. This works fine, except for those cases where the underlying field type is a dimension. I want to be able to "flatten" array types when I return them but can't see any way to do this. Any ideas anyone?

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();
     }
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about dynamics-ax-2009