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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to add recordSortedList inside RecordSortedList in X++

(0) ShareShare
ReportReport
Posted on by 10,280

Anybody tried to use record sorted list class as I am trying to iterate over it or copy it to another recordSortedList but I always get object reference null so please help if anybody gets stuck with it .

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Please refer to this:

    static void AjhTestRSL(Args _args)

    {

       CustTable custTable;

       RecordSortedList myList = new RecordSortedList(tableNum(CustTable));

       boolean moreRecs;

       myList.sortOrder(fieldNum(CustTable, AccountNum));

       // create a list

       while select firstOnly10 * from custTable

       {

           myList.ins(custTable);

       }

       // step through the list

       moreRecs = myList.first(custTable);

       while (moreRecs)

       {

           info(custTable.AccountNum);

           moreRecs = myList.next(custTable);

       }

    }

  • Codehunter Profile Picture
    10,280 on at

    Hi Leo,

    Thanks so much for your incredible description but I don't have a table to iterate over . I have only args that comes from a form and it includes recordsortedlist as  parm of type (RecordSortedList) so I need to set this recordsortedlist to another buffer of the same type.

  • Community Member Profile Picture
    on at

    If you are not clear ahout which table it contains, I suggest that you can declare a variable with type: Common instead of custTable in my sample. Then you can iterate the recordsortedlist with the common table variable and insert it to a new recordsortedlist.

  • Codehunter Profile Picture
    10,280 on at

    How could I do it ? Show me an example if possible.

  • Codehunter Profile Picture
    10,280 on at

    Actually, I got this buffer (record sorted list) from form and I need to pass it to another record sorted list but I got an error ( object reference not set to an instance of an object)

  • Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    You said "I got this buffer (record sorted list)"m, but a table buffer and a RecordSortedList instance are two different things. Please clarify whether that you're getting RecordSortedList via Args.parmObject() or a table buffer via Args.record().

    Regarding the exception, it means that you're trying to work (e.g. calling methods) with a reference that contains null. You should easily see it in debugger. If you need more help, you'll have to show us your code. Don't forget to mention which line of code is throwing the error.

  • Codehunter Profile Picture
    10,280 on at

    yes, it is args.parmObject() and am trying to call it in the batch with the following lines below:

    class FixedAssetsBatch extends RunBaseBatch

    {

        AssetBook             assetBook;

        AssetTransferBalancing assetTransfer;

       RecordSortedList assetBookList;

       Str60 defaultDimension;

         QueryRun gQueryRun;

       #define.CurrentVersion(1)

    }

    public static void main(Args _args)

       {

           RecordSortedList myRecordSortedList=new RecordSortedList(tableNum(AssetBook));

           FixedAssetsBatch    _FixedAssetsBatch = FixedAssetsBatch::construct();

           myRecordSortedList=_args.parmObject();

           _FixedAssetsBatch.assetBookListpar(myRecordSortedList);

           _FixedAssetsBatch.defaultDim(_args.parm());

           _FixedAssetsBatch.getLast();

           _FixedAssetsBatch.caption();

           _FixedAssetsBatch.run();

       }

    public  void run()

       {

         RecordSortedList list= new RecordSortedList(tableNum(AssetBook));

           list.sortOrder(fieldNum(AssetBook,recid));

          list=assetBookList;

    }

  • Codehunter Profile Picture
    10,280 on at

    this code is in the run method() and when i run this code below and it gives the object reference  in this highlighted one but at the same time, i checked the recordSortedList from arg.parms and it doesnt return null so please help

    if (!assetTransfer.transferAsset(list,str2int64(defaultDimension),today(),'Handled by Batch Job'))

                   {

                   throw error("@SYS4005928");

               }

  • Codehunter Profile Picture
    10,280 on at

    I also checked list buffer to make sure that it has values as i set a condition (if list.len()>1) do some actions and it accesses the method but the error keeps hitting so please advise

  • Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    Please always use Insert > Insert Code (in the rich-formatting view) to paste source code. Let me do it for you this time.

    First code snippet:

    class FixedAssetsBatch extends RunBaseBatch
    {
    	
    	AssetTransferBalancing assetTransfer;
    	RecordSortedList assetBookList;
    	Str60 defaultDimension;
    }
    
    public static void main(Args _args)
    {
    	RecordSortedList myRecordSortedList=new RecordSortedList(tableNum(AssetBook));
    	FixedAssetsBatch    _FixedAssetsBatch = FixedAssetsBatch::construct();
    	myRecordSortedList=_args.parmObject();
    	_FixedAssetsBatch.assetBookListpar(myRecordSortedList);
    	_FixedAssetsBatch.defaultDim(_args.parm());
    	_FixedAssetsBatch.getLast();
    	_FixedAssetsBatch.caption();
    	_FixedAssetsBatch.run();
    }
    
    public void run()
    {
    	RecordSortedList list= new RecordSortedList(tableNum(AssetBook));
    	list.sortOrder(fieldNum(AssetBook,recid));
    	list=assetBookList;
    }

    Note that this code doesn't show any iteration of a list at all. You create a RecordSortedList, then you overwrite it (therefore the initialization can be thrown away) and you pass it to FixedAssetsBatch. That's it. The run() method does nothing useful at all, it just creates an empty list and assign it to two variables.

    The latter snippet:

    if (!assetTransfer.transferAsset(list, str2int64(defaultDimension), today(), 'Handled by Batch Job'))
    {
    	throw error("@SYS4005928");
    }

    You never initialize assetTransfer variable, therefore it's null. As I told you in my previous reply, you get an exception when you're trying to call methods on null objects. I also told you that you can use the debugger to check if a value is null. Make sure you learn how to do it, so you can find such bugs by yourself next time.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 449 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 422 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans