Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

Inserting with RecordInsertList

(1) ShareShare
ReportReport
Posted on by 1,550
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 230,605 Most Valuable Professional 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,550 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;
        }
    
    }
    }
    
     

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,904 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,605 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans