简体   繁体   English

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

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

I am trying to import some values into a custom table in AX (GEACAccounts) from a CSV file. 我正在尝试从CSV文件将一些值导入AX(GEACAccounts)中的自定义表中。

Now, the code below works as expected except when I try to load a CSV file which contains a GEACaccount (Container item #3) number which already exists in the table. 现在,下面的代码可以按预期工作, 除了当我尝试加载包含表中已经存在的GEACaccount(容器项目#3)编号的CSV文件时。 In this case AX throws an error saying "Error inserting record into table. Record already exists. 在这种情况下,AX引发错误,提示“将记录插入表时出错。记录已存在。

It appears to me that this error is occurring because there is some setting on the table which does not allow duplicate values in a table, but I am not sure what this setting might be. 在我看来,发生此错误是因为表上存在某些设置,该设置不允许表中的重复值,但是我不确定此设置可能是什么。 A different field is set as the Primary Key (RecID). 另一个字段设置为主键(RecID)。 The GEACAccount field is also related to another table. GEACAccount字段也与另一个表相关。 Could this be causing my error or something else? 这可能导致我的错误或其他原因吗?

Also, this functionality is correct, there should only be one unique value of GEACAccount allowed on this table. 同样,此功能是正确的,此表上应只允许一个唯一值GEACAccount。 I am just asking as I am curious where this might be controlled from. 我只是问,因为我很好奇这可能是从哪里控制的。

Any advise on where to look next would be greatly appreciated. 任何建议下一步寻找将不胜感激。

Code below. 下面的代码。

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");
    }

}

Thanks, 谢谢,

Phil 菲尔

Go to the AOT, find the GEACAccounts table, expand the nodes to find Indexes and right click on any Index and click "Properties" to open the properties window. 转到AOT,找到GEACAccounts表,展开节点以找到Indexes然后右键单击任何Index ,然后单击“属性”以打开属性窗口。

Click up/down on each Index and look at the properties to see if AllowDuplicates = No , and for the ones where duplicates are not allowed, expand them and see what fields constitute a unique key. 单击每个Index上/下,然后查看属性以查看AllowDuplicates = No ,对于不允许重复的属性,请展开它们并查看哪些字段构成唯一键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM