web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Writes to CustCustomerV3Entity failed -- A record that has the attribute values Account Number, Company already exists

(0) ShareShare
ReportReport
Posted on by 465

Hi,
I'm trying this but I'm getting this Error:
Unable to write data to entity accounts.Writes to CustCustomerV3Entity failed with error message Request failed with status code PreconditionFailed and CDS error code : 0x80060892 response message: A record that has the attribute values Account Number, Company already exists. The entity key Account Table Key requires that this set of attributes contains unique values. Select unique values and try again

 public static void main(Args _args)
    {
        DirPartyCDSEntity associatedParty;
        CustCustomerV3Entity customer;
        System.Exception        ex;

        try
        {

            ttsbegin;
            associatedParty.PartyType = enum2Str(DirPartyType::Organization);
            associatedParty.OrganizationName = 'Org1';
            associatedParty.insert();
            ttscommit;

            ttsbegin;
            customer.CustomerGroupId  = 'CASH';
            CustGroup custGroup = CustGroup::find(customer.CustomerGroupId);
            NumberSeq numberSeq;
            if(custGroup.CustAccountNumSeq)
            {
                numberSeq             = NumberSeq::newGetNumFromId(CustGroup.CustAccountNumSeq);
            }
            else
            {
                numberSeq             = NumberSeq::newGetNum(CustParameters::numRefCustAccount());
            }

            customer.CustomerAccount = numberSeq.num();
            customer.PartyNumber  = associatedParty.PartyNumber;
            customer.PartyType  = associatedParty.PartyType;
            customer.SalesCurrencyCode = 'GBP';
            customer.SalesTaxGroup = 'STD';
            customer.insert();

            ttscommit;
        }
        catch(ex)
        {
            info(ex.Message);
        }

    }



I have the same question (0)
  • Suggested answer
    huijij Profile Picture
    19,811 on at

    Hi D365FO user,

    I did not report this error with the code. As per the error, suggest you go to the database and check if these two fields have already been inserted and are they unique keys?

  • André Arnaud de Calavon Profile Picture
    300,911 Super User 2025 Season 2 on at

    It seems like you have a customization for number sequences per customer group. I would suggest using the debugger to check if there is any number allocated or probably there is an overlap in the number sequences.

  • D365FO user Profile Picture
    465 on at

    Hi Andrea, Judy

    I've noticed that this only happens if i create a party of type org. I tried a person party type and i got no errors, then when i switched back to organization i got the error i specified in the question.

    can you please explain more how to know if the issue is in the number sequence? what do i need to do exactly?

      public static void main(Args _args)
        {
            DirPartyCDSEntity associatedParty;
            CustCustomerV3Entity customer;
            System.Exception        ex;
    
            try
            {
    
                ttsbegin;
                
                //org
                //associatedParty.PartyType = enum2Str(DirPartyType::Organization);
                //associatedParty.OrganizationName = 'Org1';
                //associatedParty.OrganizationNumOfEmployees = 10;
                //org
    
                //person
                associatedParty.PartyType = enum2Str(DirPartyType::Person);
                associatedParty.PersonFirstName = "testOn";
                associatedParty.PersonMiddleName = " MiddleNameTest";
                associatedParty.PersonLastName = "LastNameTest";
                //person
                
                associatedParty.insert();
                
                ttscommit;
    
                ttsbegin;
                customer.CustomerGroupId  = 'CASH';
                CustGroup custGroup = CustGroup::find(customer.CustomerGroupId);
                NumberSeq numberSeq;
                if(custGroup.CustAccountNumSeq)
                {
                    numberSeq             = NumberSeq::newGetNumFromId(CustGroup.CustAccountNumSeq);
                }
                else
                {
                    numberSeq             = NumberSeq::newGetNum(CustParameters::numRefCustAccount());
                }
    
                customer.CustomerAccount = numberSeq.num();
                customer.PartyNumber  = associatedParty.PartyNumber;
                customer.PartyType  = associatedParty.PartyType;
                customer.SalesCurrencyCode = 'GBP';
                customer.SalesTaxGroup = 'STD';
                customer.insert();
    
                ttscommit;
            }
            catch(ex)
            {
                info(ex.Message);
            }
    
        }

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    Do you get a value at line 42? Doesn't it already exist in CDS?

  • D365FO user Profile Picture
    465 on at

    Hi Martin,

    yes i get one and no it doesn't exist in CDS. Any idea?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 522 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans