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,278

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 .

  • Martin Dráb Profile Picture
    233,017 Most Valuable Professional on at
    RE: How to add recordSortedList inside RecordSortedList in X++

    I didn't say anything about changing a standard class.

    Your first step should be identifying the place throwing the exception. Use the debugger for that, as suggested above. When you know which reference is null, look at why it's null.

    Most likely you're passing wrong parameters to the method. For example, your handling of dimensions look pretty suspicious. But let's not guess - debug the code instead.

  • Codehunter Profile Picture
    10,278 on at
    RE: How to add recordSortedList inside RecordSortedList in X++

    i only call this method and it is a standard class in AX so how possible could i change it?

  • Martin Dráb Profile Picture
    233,017 Most Valuable Professional on at
    RE: How to add recordSortedList inside RecordSortedList in X++

    Aha, so you didn't give us complete code before. :-(

    Please use the debugger to find out where the exception is thrown and which variable is responsible for it. It seems it's somewhere inside AssetTransferBalancing.assetTransfer() method, not in any code you've shared so far.

    By the way, why didn't use Insert > Insert Code (in the rich-formatting view) to paste  source code? If you don't know how, feel free to ask.

  • Codehunter Profile Picture
    10,278 on at
    RE: How to add recordSortedList inside RecordSortedList in X++

    No, i already initiate it in the following code below:

    public boolean init()

    {

       boolean ret;

       assetBookList=new RecordSortedList(tableNum(AssetBook));

       assetBookList.sortOrder(fieldNum(AssetBook,RecId));

       assetTransfer= AssetTransferBalancing::construct();

       ret = super();

       return ret;

    }

  • Martin Dráb Profile Picture
    233,017 Most Valuable Professional on at
    RE: How to add recordSortedList inside RecordSortedList in X++

    Please read my reply more carefully. I said you don't initialize assetTransfer variable, not a RecordSortedList.

    You do initialize a list, but as I said, it's empty, because you've just created it. It has nothing to do with the object you received from _args.parmObject().

  • Codehunter Profile Picture
    10,278 on at
    RE: How to add recordSortedList inside RecordSortedList in X++

    I already initiate recordsortedList in the run method so u mean that I shouldn't initiate it in this method

  • Martin Dráb Profile Picture
    233,017 Most Valuable Professional on at
    RE: How to add recordSortedList inside RecordSortedList in X++

    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.

  • Codehunter Profile Picture
    10,278 on at
    RE: How to add recordSortedList inside RecordSortedList in X++

    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

  • Codehunter Profile Picture
    10,278 on at
    RE: How to add recordSortedList inside RecordSortedList in X++

    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,278 on at
    RE: How to add recordSortedList inside RecordSortedList in X++

    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;

    }

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,261 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,017 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans