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

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Cannot create record. The Record already exists.

(0) ShareShare
ReportReport
Posted on by 916

Hi there,

i'm trying to insert new record in table based on another object : 

In the form i create a button with clicked method .so i want when i click on the button duplicate the object with one field will be changed. i tried this : 

void clicked()
{
    NumberSequenceTable     newNumSeqTable;
    super();

    ttsBegin;
    newNumSeqTable.clear();
    newNumSeqTable.NumberSequence           =   numberSequenceTable.NumberSequence;
    newNumSeqTable.Txt                      =   "blabla";
    newNumSeqTable.NumberSequenceScope      =   numberSequenceTable.NumberSequenceScope;
    newNumSeqTable.Continuous               =   numberSequenceTable.Continuous;
    newNumSeqTable.Format                   =   numberSequenceTable.Format;
    newNumSeqTable.Highest                  =   numberSequenceTable.Highest;

    newNumSeqTable.CleanInterval            =   numberSequenceTable.CleanInterval;
    
    newNumSeqTable.insert();
    
    ttsCommit;
}

this not work . i get Error :Cannot create a record in Number sequence Scope (NumberSequenceScope). Reference: 0.The record already exists.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    XB Profile Picture
    1,875 on at
    RE: Insert new object in table

    Check non duplicate index, I think you are duplicating record 

  • ALAhmed Profile Picture
    916 on at
    RE: Insert new object in table

    yes , i have tried to customize like this :

    public static void DuplicateNumSeqByPeriod(NumberSequenceTable _numSequenceTable)
    {
        
        NumberSequenceTable     newNumSeqTable;
        FiscalCalendarPeriod    fiscalCalendarPeriod;
        NumberSequenceScope     numSequenceScope;
    
        buf2Buf(NumberSequenceScope::find(_numSequenceTable.NumberSequenceScope),numSequenceScope);
        
        while select * from fiscalCalendarPeriod
                where fiscalCalendarPeriod.FiscalCalendarYear == FiscalCalendarPeriod::find(numSequenceScope.FiscalCalendarPeriod).FiscalCalendarYear
                   && fiscalCalendarPeriod.Type               == FiscalPeriodType::Operating
                  &&  fiscalCalendarPeriod.RecId              != NumberSequenceScope::find(_numSequenceTable.NumberSequenceScope).FiscalCalendarPeriod
        //notexists join numSequenceScope 
                    //where numSequenceScope.FiscalCalendarPeriod == fiscalCalendarPeriod.RecId
        {
            numSequenceScope.FiscalCalendarPeriod = fiscalCalendarPeriod.RecId;
            numSequenceScope.insert();
            
            buf2Buf(_numSequenceTable,newNumSeqTable);
            newNumSeqTable.NumberSequenceScope =  numSequenceScope.RecId;
            newNumSeqTable.Insert();
        }
    }

    so also i have the some error

    Cannot create a record in Number sequence Scope (NumberSequenceScope). Reference: 0.The record already exists.

    The problem is on index , when i add this 

    numSequenceScope.DataArea = "othercompany"; works fine
  • Suggested answer
    XB Profile Picture
    1,875 on at
    RE: Cannot create record. The Record already exists.

    I review index and see that exists one called SeriesIdx that don't allow duplicates and have two fields NumberSequence and NumberSequenceScope so if you are copying this two values from another exist records you'll have an error.

    newNumSeqTable.NumberSequence           =   numberSequenceTable.NumberSequence;
    newNumSeqTable.Txt                      =   "blabla";
    newNumSeqTable.NumberSequenceScope      =   numberSequenceTable.NumberSequenceScope;

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 3

#3
Scott_itD Profile Picture

Scott_itD 2 Community Manager

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans