AYUDA!!!!!!!!! problemas con Importar CSV a un GRID en Dynamics AX 2012 R3

Hilo iniciado por Mario Andres Bustos Araya el 26 de enero de 2016

Viendo 10 entradas - de la 1 a la 10 (de un total de 10)
  • Autor
    Entradas
  • #10093
    RangoMario Andres Bustos ArayaMario Andres Bustos Araya
    Participante
    APRENDIZ
    999 Rincoins

    Hola Saludos! soy nuevo en AX y me cuesta un poco. hoy me pidieron hacer un formulario en donde creé un StringEdit para poder buscar un archivo CSV y dejar cargado el directorio en el StringEdit. luego de eso tengo un boton “procesar” el cual “DEBIERA” hacerse clic y llenar los datos que tiene en el CSV en un Grid creado. Mi problemas es que no se como al boton ese “procesar” hacerle un methodo que tome el CSV selecionado y cargarlo en el Grid Plis! necesito ayuda !!

    Adjuntos:

    338-Formulario.png

    #10094
    RangoXBBXBB
    Participante
    PARTICIPANTE
    1.049 Rincoins

    Hola una vez tengas la ruta puedes leer el csv con el siguiente metodo

    Adaptalo a tu modo.

    En mi caso en el método fillTmp rellenaba una tabla tmp.

    void readFileServer(FileName     _fileName)
    {
        System.IO.StreamReader  streamReader;

        System.String           sline;
        ;

        #File

        new InteropPermission(InteropKind::ClrInterop).assert();

        if (!_filename)
            throw error(strfmt(“@SYS50104”, “@SYS16423”));

        this.parmFileName(_filename);

        if (!System.IO.File::Exists(this.parmFileName()))
            throw error(strfmt(“@SYS109820”, this.parmFileName()));

        streamReader  = new System.IO.StreamReader(this.parmFileName(), System.Text.Encoding::get_UTF7());

        row++;
        sLine = streamReader.ReadLine();

        while (!System.String::IsNullOrEmpty(sline))
        {
            conRecord = str2Con(sline, “;”);

                this.fillTmp();

            sLine = streamReader.ReadLine();
            row++;
            this.parmRow(row);

         }

        streamReader.Close();

        CodeAccessPermission::revertAssert();
    }

    #10095
    RangoMario Andres Bustos ArayaMario Andres Bustos Araya
    Participante
    APRENDIZ
    999 Rincoins

    y ese metodo lo hago en el nodo dentro del boton cierto ?? porque ahí me tira error en el “parmFileName”

    #10096
    RangoXBBXBB
    Participante
    PARTICIPANTE
    1.049 Rincoins

    llámalo desde el botón pero no metas el código en el botón, ponlo en los métodos del formulario

    substituye el parmfilename por tu ruta!

    #10097
    RangoMario Andres Bustos ArayaMario Andres Bustos Araya
    Participante
    APRENDIZ
    999 Rincoins

    Ya deja ver si entiendo (disculpa si soy un poco lento) este methodo lo colocó en el nodo del formulario. luego adapto o suscribo “parmFileName” por la ruta de mi CSV y luego llamo el methodo  readFileServer desde mi botón que seria una cosa así

    public void lookup()
    {
    element.readFileServer(this);
    }

    o estoy muy perdido ?

    #10098
    RangoXBBXBB
    Participante
    PARTICIPANTE
    1.049 Rincoins

    Estas en la oscuridad y sin linterna ^^

    Yo de ti no llamaria al mètodo desde el lookup sino que me crearia un botón y desde este lo llamaria.

    #10099
    RangoMario Andres Bustos ArayaMario Andres Bustos Araya
    Participante
    APRENDIZ
    999 Rincoins

    es tan terrible esto u.u pero no hay que rendirse sjajaajaj mira!! encontré este method

    void clicked()
    {
    Dialog dialog;
    DialogField dialogFileName;
    SysOperationProgress simpleProgress;
    Filename filename;
    CommaIo csvFile;
    container readCon;
    Container filterCriteria;
    int numLines;
    int cnt;
    FileIOPermission permission;
    TextIO textIO;
    NoYesId Data;

    GridTemporal csvRead; // sample Table

    textBuffer tb = new textBuffer();
    #File
    #avifiles
    ;

    dialog = new Dialog(‘Select CSV File’);
    dialogFileName = dialog.addField(‘Filenameopen’, ‘File Name’);
    filterCriteria = [‘*.csv’];
    filterCriteria = dialog.filenameLookupFilter(filterCriteria);
    dialog.run();

    if (dialog.run())
    {
    filename = dialogFileName.value();
    if(!filename)
    info(‘Filename must be filled’);

    permission = new fileIOpermission(filename,#io_read);
    permission.assert();
    textIO = new TextIO(filename,#io_read);
    if (!textIO)
    throw error(‘Error reading file’);

    tb.fromFile(filename); //File name with Path …
    numLines = tb.numLines();
    csvFile = new CommaIo(filename, ‘r’);
    csvFile.inFieldDelimiter(”); // Delimiter…
    simpleProgress = SysOperationProgress::newGeneral(#aviUpdate, ‘Importing data’,1000);

    try
    {
    if (csvFile) //Checking for csv file.
    {
    readCon = csvFile.read();//reading the file.

    ttsbegin;
    for(cnt=1;cnt<=numLines;cnt++)
    {
    readCon = str2Con(tb.nextToken(true));
    ///csvRead.AccountType = Conpeek(readCon,1); //first column
    csvRead.AmountCurCredit = Conpeek(readCon,1); //secon column
    csvRead.AmountCurDebit = Conpeek(readCon,3); //third column
    csvRead.JournalNum = Conpeek(readCon,4); //third column
    csvRead.TransDate = Conpeek(readCon,5); //third column
    csvRead.Txt = Conpeek(readCon,6); //third column
    csvRead.Voucher = Conpeek(readCon,7); //third column
    csvRead.insert();
    }
    ttscommit;
    info(‘Records inserted’);
    }
    }
    catch
    {
    throw error(”);
    }
    }
    super();
    }

    Lo cual me llena una tabla que cree yo, lo malo es que me llena mal la tabla con puro 0. que error tiene ?

    #10100
    RangoXBBXBB
    Participante
    PARTICIPANTE
    1.049 Rincoins

    1.-Si lo ejecutas en servidor este último tal vez no te funcione

    2.-Que tipo de valor devuelven los conpeek(radCon,1 )….devuelve un real o un string? le estas metiendo un string al campo AmountCurCredit??

    #10101
    RangoMario Andres Bustos ArayaMario Andres Bustos Araya
    Participante
    APRENDIZ
    999 Rincoins

    Lo ejecuto en un servidor. pero me llena los datos sin drama. si lo que pasa es que no se como especificar de que tipo es cada uno porque en mi tabla tengo datos String, Real, Enum, Date. y si no me equivoco aquí tira todo los datos como int por que los tira a numLines.

    csvRead.AccountType = (Conpeek(readCon,1)); // este es Enum
    csvRead.AmountCurCredit = Conpeek(readCon,2); //Real
    csvRead.AmountCurDebit = Conpeek(readCon,3); //Real
    csvRead.JournalNum = Conpeek(readCon,4); //String
    csvRead.TransDate = Conpeek(readCon,5); //Date
    csvRead.Txt = Conpeek(readCon,6); //String
    csvRead.Voucher = Conpeek(readCon,7); //String

    #10102
    RangoXBBXBB
    Participante
    PARTICIPANTE
    1.049 Rincoins

    Todos los conpeek te devolverán un string básicamente porque estas leyendo un fichero plano.

    Te va a tocar montarte algo como

    csvRead.AmountCurCredit = str2num(Conpeek(readCon,2);, 123,1 ,1)

    csvRead.TransDate = str2date(Conpeek(readCon,5); …

    pero hazlo bonito créate una función no le metas uno de esto para cada línea

    Revisate el nodo AOT > System Documentation > Functions > str2….

Viendo 10 entradas - de la 1 a la 10 (de un total de 10)
  • Debes estar registrado para responder a este debate.
Carrito de compra