使用X ++代码将项目导入Ax

时间:2015-04-06 15:06:42

标签: axapta dynamics-ax-2009

我使用以下作业将项目导入Microsoft Dynamics AX 2009

static void ItemsImport(Args _args)
{
    InventTable                                 InventTable;
    container                                   c;
    TextIo                                      io;
    str 130                                     fileName;
    TextBuffer                                  b;
    integer                                     inc;
    ItemId                                      ItemId;
    AxInventTable                               axInventTable;
    ;

    fileName = @"C:\Users\mom\Desktop\Items.csv";
    b = new Textbuffer();
    io = SysLicenseCodeReadFile::openFile(fileName,'r');
    if (!io)
        throw error(strfmt("@SYS18678",fileName));
    io.inFieldDelimiter(";");
    c = io.read();
    b = new Textbuffer();

    ttsbegin;

    while (io.status() == IO_Status::Ok)
    {
        c = io.read();
        inc++;
        if (io.status() != IO_Status::Ok)
        break;
        ItemId = conpeek(c,1);
        select InventTable
            where InventTable.ItemId == ItemId;

                axInventTable =  new axInventTable();
                axInventTable.parmItemId(conPeek(c, 1));
                axInventTable.parmItemName(conPeek(c, 2));
                axInventTable.parmNameAlias(conPeek(c, 3));
                axInventTable.parmItemGroupId("PRD_CHF");
                axInventTable.parmModelGroupId("PMP");
                axInventTable.parmDimGroupId("Teinture");
                axInventTable.axInventTableModule_Sales().parmUnitId("Kg");
                axInventTable.axInventTableModule_Purch().parmUnitId("Kg");
                axInventTable.axInventTableModule_Invent().parmUnitId("Kg");
                axInventTable.parmBOMUnitId("g");

                axInventTable.axInventItemInventSetup().axInventDim().parmInventSiteId("FIMA");
                axInventTable.axInventItemPurchSetup().axInventDim().parmInventSiteId("FIMA");
                axInventTable.axInventItemInventSetup().axInventDim().parmInventSiteId("FIMA");

                axInventTable.axInventItemInventSetup().axInventDim().parmInventLocationId("MG_PRD_CHI");
                axInventTable.axInventItemPurchSetup().axInventDim().parmInventLocationId("MG_PRD_CHI");
                axInventTable.axInventItemInventSetup().axInventDim().parmInventLocationId("MG_PRD_CHI");
                axInventTable.save();
    }


    ttscommit;

    pause;
}

在表格中正确创建了记录,但是当我打开产品的默认订单设置/网站特定订单设置订单时, 所有字段仍然是灰色的,就像没有记录一样。

http://www.hostingpics.net/viewer.php?id=756928801.png

http://www.hostingpics.net/viewer.php?id=553431712.png

有人遇到过这个问题吗?我如何纠正x ++代码?

任何帮助都将不胜感激。

谢谢,

2 个答案:

答案 0 :(得分:0)

您很可能需要更改此行:

axInventTable = new axInventTable();

到这一行:

axInventTable = axInventTable::newInventTable(inventTable);

答案 1 :(得分:0)

这对我有用:

static void updateInventOrderSettings(Args _args)
{
    InventTable inventTable;
    InventItemInventSetup inventItemInventSetup;
    InventItemPurchSetup inventItemPurchSetup;
    InventItemSalesSetup inventItemSalesSetup;
    InventDim inventDim;

   ;
   ttsBegin;
   inventTable = InventTable::find("00001", true);
   inventTable.ItemGroupId = "Planning";
   //.. other inventTable fields
   inventTable.update();

   inventDim.initValue();
   inventDim.InventSiteId = "Site2";
   inventDim.inventLocationId = "ARC";
   inventDim = InventDim::findOrCreate(inventDim);

   //Site specific setup
   inventItemInventSetup.initValue();
   inventItemInventSetup.InventDimId = inventDim.inventDimId;
   inventItemInventSetup.ItemId = inventTable.ItemId;
   inventItemInventSetup.insert();

   inventItemPurchSetup.initValue();
   inventItemPurchSetup.InventDimId = inventDim.inventDimId;
   inventItemPurchSetup.ItemId = inventTable.ItemId;
   inventItemPurchSetup.insert();

   inventItemSalesSetup.initValue();
   inventItemSalesSetup.InventDimId = inventDim.inventDimId;
   inventItemSalesSetup.ItemId = inventTable.ItemId;
   inventItemSalesSetup.insert();

   //Default order settings
   inventItemInventSetup= inventItemInventSetup::findDefault(inventTable.itemId, true);
   inventItemInventSetup.InventDimIdDefault = inventDim.inventDimId;
   inventItemInventSetup.update();


   inventItemPurchSetup = inventItemInventSetup::findDefault(inventTable.itemId, true);
   inventItemPurchSetup.InventDimIdDefault = inventDim.inventDimId;
   inventItemPurchSetup.update();


   inventItemSalesSetup= inventItemInventSetup::findDefault(inventTable.itemId, true);
   inventItemSalesSetup.InventDimIdDefault = inventDim.inventDimId;
   inventItemSalesSetup.update();
   ttsCommit;
}