web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

The selected item cannot be used in this context if it is associated with an item model group where Always expense is selected.

(0) ShareShare
ReportReport
Posted on by 61

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              locinventJournalTrans;
                        InventJournalTable              inventjournaltable;
                        InventTable                     inventTable;
                        int                             row=1;
                        InventUpd_Estimated             estimated;
                        SalesLine                       SalesLine;
                        //int                             coun;


     str COMVariant2Str(COMVariant _cv, int _decimals = 0, int _characters = 0, int _separator1 = 0, int _separator2 = 0)
    {
        switch (_cv.variantType())
             {
        case (COMVariantType::VT_BSTR):
        return _cv.bStr();

        case (COMVariantType::VT_R4):
        return num2str(_cv.float(),_characters,_decimals,_separator1,_separator2);

        case (COMVariantType::VT_R8):
        return num2str(_cv.double(),_characters,_decimals,_separator1,_separator2);

        case (COMVariantType::VT_DECIMAL):
        return num2str(_cv.decimal(),_characters,_decimals,_separator1,_separator2);

        case (COMVariantType::VT_DATE):
        return date2str(_cv.date(),123,2,1,2,1,4);

        case (COMVariantType::VT_EMPTY):
        return "";

       default:
       throw error(strfmt("@SYS26908", _cv.variantType()));
                        }
               return "";
    }



      //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;
         type = cells.item(row, 1).value().variantType();
         while (cells.item(row 1, 1).value().variantType() != COMVariantType::VT_EMPTY)
        {
    locinventJournalTrans.clear();
    locinventJournalTrans.TransDate       =str2DateDMY(cells.item(row, 1).value().bStr());
    locinventJournalTrans.ItemId          =COMVariant2Str(cells.item(row, 2).value());
    locinventDim.configId                 =COMVariant2Str(cells.item(row, 3).value());
    locinventJournalTrans.initFromInventTable(InventTable::find(locinventJournalTrans.ItemId));
    locinventDim.InventSizeId             =COMVariant2Str(cells.item(row, 4).value());
    locinventDim.InventColorId            =COMVariant2Str(cells.item(row, 5).value());
    locinventDim.InventLocationId         =COMVariant2Str(cells.item(row, 6).value());
    locinventDim.InventSiteId             =COMVariant2Str(cells.item(row, 7).value())  ;
    locinventDim.inventBatchId            =COMVariant2Str(cells.item(row, 8).value());
    locinventDim.wMSLocationId            =COMVariant2Str(cells.item(row, 9).value());
    locinventDim.inventSerialId           =COMVariant2Str(cells.item(row, 10).value());
    locinventJournalTrans.MZNPurchUnit    =COMVariant2Str(cells.item(row, 11).value());
    locinventJournalTrans.Qty             =any2real(cells.item(row, 12).value().bStr());

   locinventJournalTrans.InventDimId      = InventDim::findOrCreate(locInventDim).inventDimId;


        // Insert the data into the appropriate tables.

   if (inventTable.ItemType == ItemType::Item)
   {
    inventTable.insert(true);
    }
    else
   {
    inventTable.ItemType = ItemType::Service;
    checkFailed(strFmt("@FPK270056"));
    }   
//If(InventTable::find(SalesLine.ItemID).isStocked())
//{
//estimated= InventUpd_Estimated::newInventMovement(estimated.updateNow());
//}
  //if (inventTable.ItemType == ItemType::Item && inventTable.isStocked())
//{
    //estimated = InventUpd_Estimated::newInventMovement( estimated.updateNow());
//}

            locinventJournalTrans.insert();

            ttscommit;
           // coun  ;
           // print('coun');
            row  ;
    }

         //info(int2str(coun));

           application.quit();



                            super();
                                InventJournalTrans_ds.refresh();
                                InventJournalTrans_ds.research();

    info('Done');

}

}
               While Import Excel File in Movement Journal there issues create on ItemType::Item and ItemType::Service.. 

I have the same question (0)
  • Suggested answer
    Komi Siabi Profile Picture
    13,109 Most Valuable Professional on at

    Hello Fawad Ahmad,

    You are getting this error for non-inventory items that you are trying to import. You should update your code.

    amazingax.wordpress.com/.../

  • Fawad Ahmad Profile Picture
    61 on at

    I don't  know how to write this code for as my use.  

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 428 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans