将CSV-FILE导入AX2012

时间:2017-08-16 11:43:09

标签: csv ms-office dynamics-ax-2012 dynamics-ax-2012-r3 import-csv

我正在尝试在AX 2012中导入csv-FILE (字段:FirstName,LastName,Birthdate,Jerseynumber)

class SYCImportData_Roster
{
}


public static void main(Args _args)
{
    SYCImportData_Roster    importData_Roster;
    ;

    importData_Roster = new SYCImportData_Roster();

    importData_Roster.run();
}


public void run()
{
    AsciiIo         rosterFile;
    SYCu17roster    u17RosterTable;
    FilenameOpen    filenameopen;
    container       records;
    int             totalRecords;
    #FILE
    ;

    filenameopen = this.dialog();

    rosterFile = new AsciiIo(filenameopen, #IO_READ);

    if ((!rosterFile) || (rosterFile.status() != IO_Status::Ok))
    {
        throw error("@SYC71");
    }

    rosterFile.inFieldDelimiter(#delimiterSemicolon);

    try
    {
        ttsBegin;
            while (rosterFile.status() == IO_Status::Ok)
            {
                records = rosterFile.read();

                if (!records)
                {
                    break;
                }

                totalRecords++;
                this.doForEach(records);
            }
        ttsCommit;
    }

    catch (Exception::Error)
    {
        if (rosterFile)
        {
            rosterFile.finalize();
            rosterFile = null;
        }
        throw error("@SYC70");
    }

    info(strFmt("@SYC52" + " = %1", totalRecords));

}

public FilenameOpen dialog()
{
    Dialog          dialog;
    DialogField     DF_dialogfield;
    FilenameOpen    filenameopen;
    #FILE
    ;

    dialog          = new Dialog("Kaderliste importieren");

    DF_dialogfield  = dialog.addField(extendedTypeStr(filenameopen));

    dialog.filenameLookupFilter(['csv' , '*' + #CSV, 'xlsx', '*' + #XLSX]);

    if (!dialog.run())
    {
        throw error("@SYC70");
    }

    filenameopen    = DF_dialogfield.value();

    return filenameopen;
}


private void doForEach(container _records)
{
    SYCu17roster        u17rosterTable;
    ;

    u17rosterTable.clear();

    u17rosterTable.FirstName    = conPeek(_records, 1);
    u17rosterTable.LastName     = conPeek(_records, 2);
    u17rosterTable.BirthDate    = conPeek(_records, 3);
    u17rosterTable.jerseyNumber = conPeek(_records, 4);

    u17rosterTable.insert();

}

我得到的错误:

执行代码时出错。转换函数的参数类型错误。 堆栈跟踪 (C)\ Classes \ SYCimportData_Roster \ doForEach - 第10行 (C)\ Classes \ SYCimportData_Roster \ run- line 35 (C)\ Classes \ SYCimportData_Roster \ main-line 8

我认为它必须对我的csv文件中的Birthdate字段的方式做一些事情。

示例:

汤姆;理查兹; 1990年2月28日; 12

0 个答案:

没有答案