Microsoft Dynamics AX 2012 X++ 无法插入记录。记录已存在错误

Microsoft Dynamics AX 2012 X++ Can not insert Record. Record Already Exists Error

我正在尝试将一些值从 CSV 文件导入到 AX (GEACAccounts) 中的自定义 table。

现在,下面的代码按预期工作 除了 当我尝试加载包含 GEACaccount(容器项目 #3)编号的 CSV 文件时,该编号已存在于 table。在这种情况下,AX 会抛出一条错误消息“将记录插入 table 时出错。记录已经存在。

在我看来,出现此错误是因为 table 上的某些设置不允许 table 中的重复值,但我不确定此设置可能是什么.另一个字段被设置为主键 (RecID)。 GEACAccount 字段也与另一个 table 相关。这会导致我的错误或其他原因吗?

此外,此功能是正确的,在此 table 上应该只允许一个唯一的 GEACAccount 值。我只是想问一下,因为我很好奇这可能是从哪里控制的。

任何关于下一步去哪里的建议都将不胜感激。

下面的代码。

static void Job11(Args _args)
{
 TextIo ioReader;
FileIOPermission fioPermission;
str sTempPath;
GEACAccounts Accounts;


container readCon;


try
{
    info("Begin reading file " +'C:\\testload.txt');

    fioPermission = new FileIOPermission('C:\\testload.txt',"RW");
    fioPermission.assert();

    ioReader = new TextIo('C:\\testload.txt',"R");
    ioReader.inFieldDelimiter(num2char(44));
    ioReader.inRecordDelimiter('\n');


    readCon = ioReader.read();

    if(ioReader)
    {
        //readCon = ioReader.read();
        // i++;

        while(ioReader.status() == IO_Status::Ok)
        {
             i++;


            info(conPeek(readCon,1));
            info(conPeek(readCon,2));
            info(conPeek(readCon,3));
            info(conPeek(readCon,4));


            ttsBegin;
            accounts.clear();
            accounts.initValue();
            accounts.GEACAccountGroup = 5637144826;
            accounts.AddlSecType = conPeek(readCon,1);
            accounts.CashflowMovement = conPeek(readCon,2);
            accounts.GEACAccountNumber = conPeek(readCon,3);
            accounts.GEACFlipSign = 0;
            accounts.SecurityGroup = conPeek(readCon,4);
            accounts.insert();
            ttsCommit;


        readCon = ioReader.read();

        }
    }
}
     catch(Exception::Error)
    {
        info("caught exception");
    }

}

谢谢,

菲尔

转到 AOT,找到 GEACAccounts table,展开节点找到 Indexes 并右键单击任何 Index,然后单击 "Properties"打开属性 window.

点击每个Index上的up/down,查看属性是否AllowDuplicates = No,对于不允许重复的,展开它们,看看哪些字段构成唯一键。