简体   繁体   中英

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.

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. In this case AX throws an error saying "Error inserting record into table. Record already exists.

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). The GEACAccount field is also related to another table. 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. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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