[英]How can I export an array from Dynamics AX 2009 via c#?
I'm pulling data from Dynamics AX 2009 from c# using the following code snippet. 我正在使用以下代码片段从c#中从Dynamics AX 2009中提取数据。 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();
}
}
You could check if the field is an array by (X++ code), and then work this out your way to "flatten" it: 您可以使用(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
}
}
You can always safely cast the object like this: 您总是可以像这样安全地投射对象:
var o = ax.CreateAxaptaObject() as AxaptaObject;
if(o != null)
{
...code
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.