bulk insertion issue with RecordSortedList Class in Ax2012

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…

I tested your code, and you are correct, only one record gets inserted.

I think the problem is because you are not including a value in your table1 for the sortOrder to act upon.

If I remember correctly, the recId, does not get assigned until the InsertDatabase method occurs, so there is no sort action in your case.

If you choose a sortOrder of recordSortedList.sortOrder(fieldnum(table1,id)) you should get the results you are looking for.

what you mean not including a value in your table1 for the sortOrder to act upon.

I mean you include RecId as the sort order, but you are not assigning a value to it in the record buffer prior to the ins statements. The RecId is assigned at the point of the insertDatabase call, so I don’t think it can be included in the SortOrder. I could be wrong, but apparently, it isn’t working for either of us. When I changed it to Id, it worked. I will run a couple more tests, and see what I come up with.

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));

When I modify the sortOrder to use Id, and don’t value the Id, in the record buffer prior to calling the ins method, I only get one record inserted also.

static server void insertDB()

{

RecordSortedList recordSortedList;

SamRecordInsert table1;

recordSortedList = new RecordSortedList(tablenum(SamRecordInsert));

recordSortedList.sortOrder(fieldnum(SamRecordInsert,id));

table1.clear();

table1.name=“AAAA”;

//table1.Id = 401;

recordSortedList.ins(table1);

table1.clear();

table1.name=“BBBBB”;

//table1.Id = 402;

recordSortedList.ins(table1);

recordSortedList.insertDatabase() ;

}

sure result will be the same as you said…

then how in standard application recid are using as sortorder

see the method \Classes\LedgerPostingGeneralJournalController\transferLines

newLineCollection = new RecordSortedList(tableNum(GeneralJournalAccountEntry));

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

I see your point Krishna, so the insertDatabase must not be assigning recId’s(I could be wrong about that). I was looking at the class you mention, and I suspect that the newLineCollection is being populated from another RecordSortedList that does have RecId’s valued. That’s the only way I can explain it. I am looking to see what is calling the transferlines method (it seems to be outside the class).

Please reference the following lines in that method:

haveRecord = _lineCollection.first(line);

haveRecord = _lineCollection.next(line);

I will research it some more and will post if I find a definite answer for you.

i came to know that

its temporarly its filling recid with values 1,2,3…etc from temporart table

and this reference of the table(generalJournalAccountEntry) passing to the class LedgerPostingGeneralJournalController

\Classes\LedgerVoucherTransObject\initFromLedgerPostingTransaction

generalJournalAccountEntry.RecId = _ledgerPostingTransaction.GeneralJournalAccountEntry;//recId being assigned // temporaly but at the time of insert in the table the recid value will be differnt

so by 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() ;

…let me know if there is anything i need to be correct in my statement

by the way i much appreciate for your passion towards learning …

If you look at LedgerPostingGeneralJournalController.addLine, you wil see that lineCopy.recId is being assigned the this.getNextTemporaryRecId();

This could take a while to trace back, but look at addCore, addLine, and transferReferences, and I think you will find that the recId is being assigned.

public RecId getNextTemporaryRecId()

{

nextTempRecId++;

return nextTempRecId;

}

I believe the recId to be temporary though, and that the insertDatabase will ultimately assign the real recId.

Nice work Krishna