Monday 27 October 2014

Import Vendor Balances In Microsoft Dynamics Axapta 2012

Here I'm sharing code to import Vendor Opening Balances Lines.

Note : The below code import only Lines.


-> Copy and paste below code in AOT->Jobs(Compile Job before using)
->open excel and fill the data according to the below format and save in CSV format
->Run job and browse file and press ok

Csv Format :

column1 - Journal Number
column2 - MainAccountNum
column3 - Dimension1
column4 - Dimension2
column5 - Dimension3
column6 - Debit Amount
column7 - Credit Amount
column8 - Transaction Date
Column9 - Description
Column10 - InvoiceId
Column11 - PostingProfile

//Code Starts From Here- @ Rahul Talasila

static void VendorOpeningBalances(Args _args)
{
    CommaIO                   csvFile;
    container                 readCon;
    counter                   icount,inserted;
    Dialog                    dialog;
    DialogField               dfFileName;
    FileName                  fileName;
    LedgerJournalACType       ledgerJournalACType;
    AxLedgerJournalTable      axLedgerJournalTable ;
    AxLedgerJournalTrans      axLedgerJournalTrans;
    container                 accPatternvend,accPatternledger;
    container                 offSetPattern;
     DimensionDynamicAccount   ledgerdimension;
   str transdate;
    ;
     inserted =0;
    #File
    dialog     = new Dialog("Pick the file");
   // dialog
    dfFileName = dialog.addField(extendedTypeStr(FileNameOpen));
    dialog.filenameLookupFilter(["All files", #AllFiles]);
    if(dialog.run())
    {
       filename =  dfFileName.value();
    }
       csvFile  =  new CommaIO(filename,'r');

    if(csvFile)
    {
        ttsBegin;
        while (csvFile.status() == IO_Status::OK)
        {
          readCon  = csvFile.read();
          if(readCon)
            {
                transdate = conPeek(readCon, 8);
                axLedgerJournalTable = new AxLedgerJournalTable();
                axLedgerJournalTrans = new AxLedgerJournalTrans();
                axLedgerJournalTrans.parmJournalNum(conPeek(readCon, 1));
                axLedgerJournalTrans.parmTransDate(str2Date(transdate,123));
                axLedgerJournalTrans.parmAccountType(LedgerJournalACType::Vend);
                ledgerdimension = DimensionStorage::getDynamicAccount(conPeek(readCon, 2), LedgerJournalACType::Vend);
                axLedgerJournalTrans.parmLedgerDimension(ledgerdimension);
                axLedgerJournalTrans.parmDefaultDimension(LedgerJournalTable::find(conPeek(readCon, 1)).DefaultDimension);
                axLedgerJournalTrans.parmAmountCurDebit(conPeek(readCon, 6));
                accPatternledger = [conPeek(readCon,2) + conPeek(readCon,3) + conPeek(readCon,4) + conPeek(readCon,5), conPeek(readCon,2),conPeek(readCon,3),conPeek(readCon,4),conPeek(readCon,5)];
                axLedgerJournalTrans.parmOffsetAccountType(LedgerJournalACType::Ledger);
                axLedgerJournalTrans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId(accPatternledger));
                axLedgerJournalTrans.parmAmountCurCredit(conPeek(readCon, 7));
                axLedgerJournalTrans.parmTxt(conPeek(readCon,9));
                axLedgerJournalTrans.parmInvoice(conPeek(readCon,10));
                axLedgerJournalTrans.parmPostingProfile(conPeek(readCon,11));
                axLedgerJournalTrans.save();
                icount++;
                inserted++;
            }
        }
      ttsCommit;
    }
   info(strfmt("%1 records Inserted out of %2",inserted,icount));

}


Note : Based on ledger account dimension structure your account pattern will change

@ Rahul Talasila

2 comments:

  1. This particular is usually apparently essential and moreover outstanding truth along with for sure fair-minded and moreover admittedly useful My business is looking to find in advance designed for this specific useful stuffs… Microsoft Dynamics 365 Sales Credit Card Processing

    ReplyDelete
  2. This is a good common sense Blog. Very helpful to one who is just finding the resources about this part. It will certainly help educate me. MB-220: Microsoft Dynamics 365 Marketing

    ReplyDelete

Adding a newline into a string in C# and X++

Below is the sample code we can use for  adding a newline after every occurrence of "@" symbol in the string in C#   using System...