0

I am trying to Import a csv-FILE in AX 2012 (Fields: 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();

}

The Error I get:

Error executing Code. Wrong type of Argument for conversion function. Stack trace (C)\Classes\SYCimportData_Roster\doForEach - line 10 (C)\Classes\SYCimportData_Roster\run- line 35 (C)\Classes\SYCimportData_Roster\main- line 8

I think it has to do something with the way the Birthdate field ist in my csv file.

Example:

Tom;Richards;28.02.1990;12

Khashayar
  • 47
  • 2
  • 15
  • People, never mind. I fixed it. Here the solution u17rosterTable.BirthDate = str2Date(conPeek(_records, 3),3); doForEach Method Line 10 – Khashayar Aug 16 '17 at 12:06
  • Could you write your solution as an answer? This way this question would be listed as answered, which helps others to find the solution more quickly. – FH-Inway Aug 24 '17 at 13:53

0 Answers0