Quantcast
Channel: Microsoft Dynamics AX Forum - Recent Threads
Viewing all articles
Browse latest Browse all 72043

Import Excel data in invent journal movement lines. But there is a calculation behind MZNqty and Costprice fields. The issue is that records of these fields not import in lines.

$
0
0

void clicked()
{

                        Dialog                          dialog;
                        DialogField                     dialogField;
                        FileName                        filename;
                        SysExcelApplication             application;
                        SysExcelWorkbooks               workbooks;
                        SysExcelWorkbook                workbook;
                        SysExcelWorksheets              worksheets;
                        SysExcelWorksheet               worksheet;
                        SysExcelCells                   cells;
                        COMVariantType                  type;

                        InventDim                                   locinventDim,locToInventDim;
                        InventJournalTrans                          inventJournalTrans;
                        //InventJournalTable                          inventjournaltable;
                        InventTable                                 inventTable;
                        InventJournalName                         inventJournalName;
                        InventJournalNameid                           inventJournalNameid;
                        DimensionAttributeValueCombination          dimAttrValueCombo;
                        JournalId                                   journalId1;
                          InventTransferLine             inventTransferLine;
                        int                                  row=2;
                        int                                 numOfLines = 0;
                       // str                         _mainAccount='110110';
                       //int                             coun;
                        //JournalCheckPost inventJournalCheckPost;


      //Define File name.
          dialog = new Dialog("Select file");
          dialogField = dialog.addField(extendedTypeStr("FileNameOpen"),"Select File Source");
          if (dialog.run())     {
          fileName = dialogField.value();
              }
          if (fileName)
              {
           application = SysExcelApplication::construct();
           workbooks = application.workbooks();
          //Open Excel workbook.
          try    {
                   workbooks.open(filename);
                  }
          catch (Exception::Error)    {
                 throw error("File cannot be opened.");
                 }
             //Open Excel Sheet
             workbook = workbooks.item(1);
             worksheets = workbook.worksheets();
             worksheet = worksheets.itemFromNum(1);//which shows excel sheet number.
             cells = worksheet.cells();

        ttsbegin;
                  try
{
        //Below code creates journal header
        inventJournalTable.clear();



        inventJournalTable.JournalNameId = this.COMVariant2Str(cells.item(row,1).value());
        inventJournalName = InventJournalName::find(this.COMVariant2Str(cells.item(row,1).value()));
        inventJournalTable.initFromInventJournalName(inventJournalName);
        info(strFmt("JournalNameId: %1", inventJournalTable.JournalNameId));
        inventJournalTable.Description    =this.COMVariant2Str(cells.item(row,2).value());
        inventJournalTable.SystemBlocked = true;
        inventJournalTable.insert();
    }
                  catch             //(Exception::Error)
                  {
                      throw error("error here");
                   //info(strFmt("Error while importing data. Journal name ID: %1", inventjournaltable.journalNameId));
                  }

         ttscommit;

         type = cells.item(row, 1).value().variantType();
         while (cells.item(row, 1).value().variantType() != COMVariantType::VT_EMPTY)


         {
       //**********************************************************Start
         ttsbegin;
         //Below code creates  lines
        inventJournalTrans.clear();
        inventJournalTrans.initFromInventJournalTable(inventJournalTable);
        inventJournalTrans.TransDate            =cells.item(row, 3).value().date();                               //systemDateGet();
        info(strFmt(this.COMVariant2Str(cells.item(row, 4).value())));
        inventJournalTrans.ItemId               =this.COMVariant2Str(cells.item(row, 4).value());                      //Replace the ItemId according to your data
        inventJournalTrans.initFromInventTable(InventTable::find(inventJournalTrans.ItemId));

        inventJournalTrans.Qty                  =any2real(cells.item(row, 16).value().bStr());

             info(strFmt(this.COMVariant2Str(cells.item(row, 18).value())));
              info(strFmt(this.COMVariant2Str(cells.item(row, 19).value())));
        inventJournalTrans.MZNQty               =any2real(cells.item(row, 18).value().bStr());        //Replace the Qty according to your data
        inventJournalTrans.CostPrice            =any2real(cells.item(row, 19).value().bStr());
        inventJournalTrans.InventDimId = InventdIm::findOrCreate(locinventDim).inventDimId;
            locinventDim = InventDim::findOrCreate(locinventDim);





            //***** S
    locinventDim.initFromInventTable(inventJournalTrans.inventMovement().inventTable(),InventItemOrderSetupType::Invent,locinventDim);
    locinventDim.configId                 =this.COMVariant2Str(cells.item(row, 5).value());
    locinventDim.InventSizeId             =this.COMVariant2Str(cells.item(row, 6).value());
    locinventDim.InventColorId            =this.COMVariant2Str(cells.item(row, 7).value());
    locinventDim.InventStyleId            =this.COMVariant2Str(cells.item(row, 8).value());
    locinventDim.inventBatchId            =this.COMVariant2Str(cells.item(row, 11).value());
    locinventDim.wMSLocationId            =this.COMVariant2Str(cells.item(row, 12).value());
    locinventDim.inventSerialId           =this.COMVariant2Str(cells.item(row, 13).value());
    locinventdim.InventSiteId             =this.COMVariant2Str(cells.item(row, 9).value());                  //Replace the InventSiteId (Site) according to your data
    locinventdim.InventLocationId         =this.COMVariant2Str(cells.item(row, 10).value());                //Replace the InventLocationId (Warehouse) according to your data
    inventJournalTrans.InventDimId        =InventdIm::findOrCreate(locinventDim).inventDimId;
    inventJournalTrans.MZNPurchUnit       =this.COMVariant2Str(cells.item(row, 17).value());
             //*****    E

                   dimAttrValueCombo.clear();
        select firstonly RecId from  dimAttrValueCombo
            where dimAttrValueCombo.MainAccount == MainAccount::findByMainAccountId(this.COMVariant2Str(cells.item(row, 21).value())).RecId //Replace the MainAccountId according to your data
            && dimAttrValueCombo.DisplayValue == this.COMVariant2Str(cells.item(row, 21).value());  //Replace the MainAccountId according to your data
            inventJournalTrans.LedgerDimension = dimAttrValueCombo.RecId;

            //inventJournalTrans.insert();
        //Insert line to movement journal if quantity is non-zero
        if(inventJournalTrans.MZNQty > 0)
        {
             inventJournalTrans.MZNQty          = inventJournalTrans.MZNQty * -1;

        }

              numOfLines++;
              inventJournalTrans.insert();

              row++;
             //numOfLines++;

             journalId1=InventJournalTable.JournalId;
             info(strFmt(journalId1));

            update_recordSet inventJournalTable
            setting SystemBlocked = false, NumOfLines = numOfLines
            where inventJournalTable.JournalId == journalId1;

        ttscommit;


       info('Done');



       //********************************************************** END

            //coun++;
            //print('coun');
         //info(int2str(coun));

        inventJournalTable.NumOfLines = numOfLines;
       // inventJournalTable.update();

          //info(strFmt("Movement Journal ID: %1", inventJournalTable.JournalId));




                  //  application.quit();

                  super();

                            InventJournalTable_ds.refresh();
                            InventJournalTable_ds.research();

}
}
}

I am beginner  at using Dynamic AX 2012.  If few changes are  required in my code. please guide me .

But there is calculation behind MZNqty  and Costprice fields.The issue is that records of these fields not import in lines.


Viewing all articles
Browse latest Browse all 72043

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>