问题通过x ++导入转移日记帐

问题描述 投票:1回答:1

我有以下问题:以下代码可以正常工作:

inventJournalTrans.clear();
inventJournalTrans.initFromInventJournalTable(inventJournalTable);
inventJournalTrans.ItemId = "100836M";

frominventDim.InventLocationId="SD";
frominventDim.wMSLocationId = '11_RECEPTION';
fromInventDim.InventSizeId = '1000';
fromInventDim.inventBatchId = 'ID057828-CN';

ToinventDim.InventLocationId = "SD";
ToInventDim.wMSLocationId = '11_A2';
ToInventDim.InventSizeId = '1000';
ToInventDim.inventBatchId = 'T20/0001/1';

ToinventDim = InventDim::findOrCreate(ToinventDim);
frominventDim = InventDim::findOrCreate(frominventDim);

inventJournalTrans.InventDimId = frominventDim.inventDimId;
inventJournalTrans.initFromInventTable(InventTable::find("100836M"));
inventJournalTrans.Qty = -0.5;
inventJournalTrans.ToInventDimId = ToinventDim.inventDimId;
inventJournalTrans.CostAmount = InventJournalTrans.calcCostAmount(-abs(any2real(strReplace('-0.5',',','.'))));
inventJournalTrans.TransDate = SystemDateget();
inventJournalTrans.insert();

inventJournalCheckPost = InventJournalCheckPost::newJournalCheckPost(JournalCheckpostType::Post,inventJournalTable);
inventJournalCheckPost.parmThrowCheckFailed(_throwserror);
inventJournalCheckPost.parmShowInfoResult(_showinforesult);
inventJournalCheckPost.run();

它会正确创建传输日记帐行并成功过帐传输日记帐。

我的要求是从csv文件导入日记帐行。我写了以下代码:

    inventJournalTrans.clear();
    inventJournalTrans.initFromInventJournalTable(inventJournalTable::find(_journalID));
    InventJournaltrans.ItemId             = conpeek(_filerecord,4);

    inventDim_From.InventLocationId       = 'SD';
    inventDim_From.wMSLocationId          = '11_RECEPTION';
    InventDim_from.InventSizeId           = conpeek(_fileRecord,11);
    InventDim_From.inventBatchId          = strfmt("%1",conpeek(_fileRecord,5));

    InventDim_To.InventLocationId         = 'SD';
    inventDim_To.wMSLocationId            = strfmt("%1",conpeek(_fileRecord,10));
    InventDim_To.InventSizeId             = conpeek(_fileRecord,11);
    InventDim_To.inventBatchId            = strfmt("%1",conpeek(_fileRecord,6));

    InventDim_From                        = InventDim::findOrCreate(inventDim_From);
    inventDim_To                          = InventDim::findOrCreate(inventDim_To);

    InventJournalTrans.InventDimId = inventDim_From.inventDimId;
    InventJournalTrans.initFromInventTable(InventTable::find(conpeek(_filerecord,4)));
    inventJournalTrans.Qty                = -abs(any2real(strReplace(conpeek(_fileRecord,8),',','.')));
    inventJournalTrans.ToInventDimId      = inventDim_To.inventDimId;
    InventJournalTrans.CostAmount         = InventJournalTrans.calcCostAmount(-abs(any2real(strReplace(conpeek(_fileRecord,8),',','.'))));
    inventJournalTrans.TransDate          = str2date(conpeek(filerecord,9),123);
    InventJournalTrans.insert();

当我使用insert()方法时,出现以下错误:itemId不存在size。当我在inventSize表中查看我的itemId时,大小存在,我认为这是inventJournalTrans中的inventDimId问题,但它们与第一个代码示例严格相似。我所有的数据都与第一个示例相同,但不是硬编码的,并且来自读取我的csv文件。

我花了很多时间进行调试,没有发现任何错误,但仍然存在错误消息

非常感谢您的帮助。

axapta x++ dynamics-ax-4
1个回答
0
投票

当您从文件读取时,请始终修剪尾随空格。您可以使用strRtrim功能执行此操作。

例如:

InventDim_To.InventSizeId = strRtrim(conpeek(_fileRecord,11));
© www.soinside.com 2019 - 2024. All rights reserved.