Skip to main content

Notifications

Dynamics 365 Community / Forums / Finance forum / Inserting with RecordI...
Finance forum
Suggested answer

Inserting with RecordInsertList

Posted on by 1,548
Hi,

I have a customized table with the following properties:
cache lookup: NotInTTS
Table Group: Transaction
AllowRowVersionChangeTracking: Yes
ValidTimeStateFieldType: None
The insert method doesn't have any code
 
Currently I'm inserting to this table using RecordInsertList  via batch. However i can see that records are being inserted to the table even though the batch is still executing. And the number of records inserted increases each certain amount of time. So it seems InsertToDatabase is not inserting eveything at once, it's inserting each group together. I'm currently importing more than 100,000 record.  At first the were around 240 records then i selected the table in SQL and they suddenly became 790, then 1370 etc..
Shouldn't it insert them all at once or is this normal? or is there a fallback?

i'll put the code in the first comment so that the code appears clearly
 
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 227,996 Super User 2024 Season 2 on at
    Inserting with RecordInsertList
    That's correct - the purpose of RecordInsertList is not holding all records in memory and insert them at once. It inserts records in smaller chunks automatically; insertToDatabase() is used at the end to process remaining records that haven't been inserted yet.
     
    If you aren't sure how something should work, you can look into documentation: RecordInsertList Class.
  • junior AX Profile Picture
    junior AX 1,548 on at
    Inserting with RecordInsertList
    Imagine code starts with run method
    class x extends classZBatch
    {
      private RecordInsertList  recordInsertList = new RecordInsertList(tableNum(TableA));
    
      public void run()
      {
        this.process();
        this.postProcess();
      }
    
      public void postProcess() {
    
        recordInsertList.insertDatabase();
      }
    
      void process() 
      {
        str line;
        const str fieldDelimiter = '\r\n';
        const str recordDelimiter = '\r\n';
        importFile.inFieldDelimiter(fieldDelimiter);
        importFile.inRecordDelimiter(recordDelimiter);
        while (importFile.status() == IO_Status::Ok)
        {
          line = conPeek(importFile.read(), 1);
    
          ttsbegin;
    
          this.processLine(line);
    
          ttscommit;
    
        }
      }
      protected void processLine(str _line) 
      {
        ClassA process = classA::newFromEnumX(EnumX::First);
        process.insertTableA(_line);
        recordInsertList = process.getRecordInsertList();
      }
    }
    
    
    abstract class classA
    {
        private TableA   tableA;
    
        private RecordInsertList recordInsertList = new RecordInsertList(tableNum(TableA));
    
    
        final public void insertTableA(str _line)
        {
    
            tableA.clear();
            // logic to fill table A
            
            recordInsertList.add(tableA);
    
        }
    
    
        public static ClassA newFromEnumX(EnumX _enumX)
        {
            EnumXAtrribute enumXAttribute = new EnumXAtrribute(_enumX);
            return SysExtensionAppClassFactory::getClassFromSysAttribute(classStr(ClassA), enumXAttribute);
        }
    
    
        public RecordInsertList getRecordInsertList()
        {
            return recordInsertList;
        }
    
    
    }
    
    
    class EnumXAtrribute extends SysAttribute implements SysExtensionIAttribute
    {
        EnumX enumX;
    
        public void new(EnumX _enumX)
        {
            super();
    
            enumX = _enumX;
        }
    
        public str parmCacheKey()
        {
            return classStr(EnumXAtrribute) + ';'+ int2str(enum2int(enumX));
        }
    
        public boolean useSingleton()
        {
            return true;
        }
    
    }
    }
    
     

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,186 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 227,996 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans