mercredi 21 décembre 2011

How to import customers using a csv file in dynamics ax

Here is an example of a job that can be used to import customers

static void insert_Clients_Stunas(Args _args)
{
        CustTable                                   custTable;
        container                                   c;
        Integer                                     Start, PartyStart;
        TextIo                                      io;
        string50                                    fileName, FRS;
        TextBuffer                                  b;
        DirPartyType                                DirPartyType;
        ExtendedTypeId                              id;
        NumberSeq                                   num;
        DirPartyId                                  localDirPartyId;
        DirpartyTable                               dirpartyTable, _dirpartyTable;
        AccountNum                                  AccountNum;
        Addressing                                  address;
        Address                                     addressTab;
        CustPaymModeTable                           custPaymModeTable;
        Name                                        PaymName;

        ;
        delete_from custTable;

        fileName = @"C:\\Update_Clients_Stunas\Clients.csv";
        b=new Textbuffer();
         io = SysLicenseCodeReadFile::openFile(fileName,'r');

         c = io.read();
         if (!io)
            throw error(strfmt("@SYS18678",fileName));
         io.inFieldDelimiter(";");

         while (io.status() == IO_Status::Ok)
         {
             c = io.read();
             AccountNum                         = conpeek(c,1);
             custTable.AccountNum               = AccountNum;
             custTable.PartyId                  = AccountNum;

             custTable.Name                     = conpeek(c,2);
             custTable.NameAlias                = conpeek(c,2);
             custTable.CustGroup                = conpeek(c,16);
             custTable.Currency                 = "TND";
             custTable.PartyType                = DirPartyType::Organization;
             custTable.LanguageId               = "FR";
             custTable.TaxGroup                 = conpeek(c,6);
             custTable.VATNum                   = conpeek(c,7);

             custTable.Phone                    = conpeek(c,8);
             custTable.CellularPhone            = conpeek(c,9);
             custTable.TeleFax                  = conpeek(c,10);
             custTable.InvoiceAccount           = conpeek(c,11);
             custTable.SegmentId                = conpeek(c,12);
             custTable.PriceGroup               = conpeek(c,13);
             PaymName                           = conpeek(c,15);
             custTable.CustGroup                = conpeek(c,16);
             custTable.editContactPersonName(true, conpeek(c,17));
             if(conpeek(c,18) != '*')
             custTable.SubsegmentId             = conpeek(c,18);

             select PaymMode from custPaymModeTable
                where custPaymModeTable.Name    == PaymName;
             custTable.PaymMode                 = custPaymModeTable.PaymMode;

             custTable.insert();

             delete_from DirpartyTable
                where DirpartyTable.PartyId == accountNum;


             DirpartyTable.Type                 = DirPartyType::Organization;
             DirpartyTable.Name                 = conpeek(c,2);
             DirpartyTable.NameAlias            = conpeek(c,2);
             DirpartyTable.LanguageId           = "FR";
             DirpartyTable.PartyId              = AccountNum;

             print custTable.AccountNum;
             print custTable.Name;
             print dirpartytable.PartyId;

             DirpartyTable.insert();



             select recId from _dirpartytable
                where _dirpartytable.RecId   == dirpartytable.RecId
                    && dirpartytable.PartyId == AccountNum;
                    print _dirpartytable.RecId;
             addressTab.AddrRecId        = _dirpartytable.RecId;
             addressTab.AddrTableId      = 2303;
             addressTab.State            = conpeek(c,4);
             addressTab.Street           = conpeek(c,3);
             addressTab.ZipCode          = conpeek(c,5);

             addressTab.insert();
    }

    info("finish");
}

Aucun commentaire:

Enregistrer un commentaire