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 pass element.args().parmObject() to Batch Class that extends runbasebatch

(0) ShareShare
ReportReport
Posted on by 10,278

i tried to set element.args().parmObject() to pass it to batch class but i always get an error mentioning An object reference not set to an instance of object.

Please help.

  • Suggested answer
    Martin Dráb Profile Picture
    233,013 Most Valuable Professional on at
    RE: how to pass element.args().parmObject() to Batch Class that extends runbasebatch

    Yes, I know you would, but I explicitly told you that it's impossible, explained why and described a way how you can achieve your goal, including giving you code. What else can I do?

    All right, let me repeat it once more. You can't pass objects to batch. You must serialize objects to primitive data types, store them in a container and this container can be saved to database for batch processing. A usual way to serialize objects to a container is using pack() method. This is true for both RunBase classes and SysRecordSortedList class. I told you before that SysRecordSortedList the benefit of SysRecordSortedList is that it supports packing.

    The code I gave you shows calling pack() on SysRecordSortedList object to get a container for the list and then adding it to your RunBase class (its pack() method is then called by the framework).

    Let me suggest for the third time that you should open the links about packing that I gave you and read the content. Things would make better sense to you if you learnt a bit about them.

  • Codehunter Profile Picture
    10,278 on at
    RE: how to pass element.args().parmObject() to Batch Class that extends runbasebatch

    i would like to know how to pass this type of object inside the container as the method i call has recordSortedList in its arguments so please advise.

  • Martin Dráb Profile Picture
    233,013 Most Valuable Professional on at
    RE: how to pass element.args().parmObject() to Batch Class that extends runbasebatch

    If it's not obvious that container and RecordSortedList are two different types, you can try it and you'll see whether the compiler complains about assigning values of wrong types.

    When you finish this exercise, remove the change you made in my code, which broke the whole thing.

  • Codehunter Profile Picture
    10,278 on at
    RE: how to pass element.args().parmObject() to Batch Class that extends runbasebatch

    Thanks a lot,Martin for clarification but i have one more thing to ask about. the object i need to pass from form to batch is of type RecordSortedList so is it possible to call mybatch.parmPackedList(_args.parmObject()) or it will throw an error?

  • Suggested answer
    Martin Dráb Profile Picture
    233,013 Most Valuable Professional on at
    RE: how to pass element.args().parmObject() to Batch Class that extends runbasebatch

    Please make sure you give us your actual code. Looking at different code than you're using makes little sense.

    What I told you apply to all objects, including SysRecordSortedList - you can't put them into containers and let them stored in batch tables. But as I told you before SysRecordSortedList has a pack() method that you can call to get the list serialized to a container. Therefore you can use a container as your instance variable:

    class FixedAssetsBatch extends RunBaseBatch
    {
    	container packedList;
    	DimensionDefault defaultDimension;
    	
    	#define.CurrentVersion(1)
    	#define.Version1(1)
    	#localmacro.CurrentList
    		defaultDimension,packedList
    	#endmacro
    	
    	public container pack()
    	{
    		return [#CurrentVersion,#CurrentList];
    	}
    	
    	public container parmPackedList(container _packedList = packedList)
    	{
    		packedList = _packedList;
    		return packedList;
    	}
    }
    

    and call pack() method on the list before assigning it to the container:

    myBatch.parmPackedList(sortedList.pack());

  • Andre Ghazaleh Profile Picture
    870 on at
    RE: how to pass element.args().parmObject() to Batch Class that extends runbasebatch

    Martin means to use the "Use rich Formatting" when posting to this forum to insert code, it makes it more readable. Copying and pasting directly without using insert will make the code messy and hard to read.

    pastedimage1603481621914v1.png

    Regards

  • Codehunter Profile Picture
    10,278 on at
    RE: how to pass element.args().parmObject() to Batch Class that extends runbasebatch

    Sorry, i mean SysRecordSortedList

    but i need to know how to call insert and what method i should use insert.

  • Martin Dráb Profile Picture
    233,013 Most Valuable Professional on at
    RE: how to pass element.args().parmObject() to Batch Class that extends runbasebatch

    What is SysSortedList? I guess it's a collection class and you can't assign object references to the container. Even it it didn't throw an error, it would make no sense. Object references are addresses in memory and they don't have the same meaning on other computers. Don't you want to read again the resource I gave you about packing?

    By the way, you again forgot to use Insert > Insert Code when pasting source code. Please do it in future.

  • Codehunter Profile Picture
    10,278 on at
    RE: how to pass element.args().parmObject() to Batch Class that extends runbasebatch

    Here is my code below:

    class FixedAssetsBatch extends RunBaseBatch

    {

       AssetTransferBalancing assetTransfer;

      SysSortedList assetBookList;

      DimensionDefault defaultDimension;

       #define.CurrentVersion(1)

      #define.Version1(1)

      #localmacro.CurrentList

    defaultDimension,assetBookList

      #endmacro

    public container pack()

      {

        return  [#CurrentVersion,#CurrentList]; ///Error hits in this line

      }

    }

  • nmaenpaa Profile Picture
    101,158 Moderator on at
    RE: how to pass element.args().parmObject() to Batch Class that extends runbasebatch

    Is there any chance to see your code? Which line throws the error? 

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,013 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans