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

bulk insertion issue with RecordSortedList Class

(0) ShareShare
ReportReport
Posted on by 3,006

Hi guys,

am going to insert bulk of records in my custom table using  RecordSortedList ,,

one record is being inserted in the table instead of multiple records,

a) i created a class 

b) created a method in the table

static server void insertDB()

{

   RecordSortedList recordSortedList;

  table1                      table1;

 recordSortedList   = new RecordSortedList(tablenum(table1));

    recordSortedList.sortOrder(fieldnum(table1,recid));

   table1.clear();

    table1.name="AAAA";

   table1.Id = 401;

    recordSortedList.ins(table1);

  table1.clear();

    table1.name="BBBBB";

   table1.Id = 402;

    recordSortedList.ins(table1);

  recordSortedList.insertDatabase() ;

}

c) created a main method in class called the static method with

public static   void main(Args args)

{

class1::insertDB();

}

when i checked in the table only one record (last one with id 402 ) is inserted instead of two records..

 

could you please let me know cause for this...

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    cpironmo Profile Picture
    2 on at

    Firstly can I ask why your have chosen to used RecordSortedList and not RecordInsertList?

    Also when setting the sort order, you have selected RecId but this won't be available as this is set when the records are actually created. I know the sort order needs to be specified so I would look to change this to id or name fields.

  • krishna.rao@dax Profile Picture
    3,006 on at

    Thanks for the response,,

    am trying to do with RecordSortedList ..

    please could you address below queries

    a)why should i use RecordInsertList instead of RecordSortedList ...

     i found use of RecordSortedList  no of places in standard AX app.

    b) is RecId use of sort order  will cause of single record insertion in RecordSortedList ...

       if yes how in standard app using Recid as sortorder in RecordSortedList

    much appreciate for your suggesition..

    regards,

    Krishna..

  • Suggested answer
    cpironmo Profile Picture
    2 on at

    From what I understand the RecordSortedList is used to achieve a subset of data similarly to a TemporaryTable but with some benefits with regasrds to performance.

    With records to sorting on the RecId, by taking a subset of data that is already created in the system the RecId's will be present and as such I think this may be the cause of your issue.

    If you are wanting to insert records into a table then you should utilise the RecordInsertList instead. This should then solve your issue.

  • krishna.rao@dax Profile Picture
    3,006 on at

    yes i will get the desired result by either using recordinesertList or recordSortedList using sort order other than recid..

    but here am not getting why its not inserting multiple records with recid sort order..

    as i already noticed recId used in standard app..

    see the method \Classes\LedgerPostingGeneralJournalController\transferLines

       newLineCollection = new RecordSortedList(tableNum(GeneralJournalAccountEntry));

       newLineCollection.sortOrder(fieldNum(GeneralJournalAccountEntry, RecId));

  • Verified answer
    krishna.rao@dax Profile Picture
    3,006 on at

    here \Classes\LedgerPostingGeneralJournalController\transferLines  table GeneralJournalAccountEntry also holds recId  temporarly

    so in order to use recid as sortorder i should hold value..

    in this scenario it would be better to don't use the field recid for sorting..

    changing my code will insert the multiple records..

    recordSortedList.sortOrder(fieldnum(table1,recid));

      table1.clear();

       table1.name="AAAA";

      table1.Id = 401;

    table.recid =1;

       recordSortedList.ins(table1);

     table1.clear();

       table1.name="BBBBB";

      table1.Id = 402;

    table.recid = 2;

       recordSortedList.ins(table1);

     recordSortedList.insertDatabase() ;

    thanks Chris Ironmonger

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
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans