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

parameter is not passed correctly to the class

(0) ShareShare
ReportReport
Posted on by 795

Hello,

I have a batch class which is scheduled to be run at a particular time.

There is a bellow following piece of code inside:

  while (qr.next())
    {
        salesTable = qr.get(tableNum(SalesTable));

        setPrefix(salesTable.SalesId);

        if (this.process_check(onlyCustStorageFactor))
        {
            salesResrveForMultiThread = new SalesResrveForMultiThread();
            salesResrveForMultiThread.parmsalestable(salesTable);
            salesResrveForMultiThread.pack();
            this.batchHeader().addRuntimeTask(salesResrveForMultiThread, this.parmCurrentBatch().RecId, BatchConstraintType::And);
            salesResrveForMultiThread = null;

            //salesResrveForMultiThread.run();
            i  ;

        }
        n  ;
    }

Parameter salestbale isn't passed to the class SalesReserveForMultiThread. It gets null value and then gives me an error of course.

When I launch it manually and do not create runtimetasks parameter is passed correctly like that:

  while (qr.next())
    {
        salesTable = qr.get(tableNum(SalesTable));

        setPrefix(salesTable.SalesId);

        if (this.process_check(onlyCustStorageFactor))
        {
            salesResrveForMultiThread = new SalesResrveForMultiThread();
            salesResrveForMultiThread.parmsalestable(salesTable);
            salesResrveForMultiThread.pack();
            /*this.batchHeader().addRuntimeTask(salesResrveForMultiThread, this.parmCurrentBatch().RecId, BatchConstraintType::And);
            salesResrveForMultiThread = null;*/

            salesResrveForMultiThread.run();
            i  ;

        }
        n  ;
    }

So it seems like the problem is something to do with the runtimetasks. They are created correctly but inside them I get an error that salestable buffer is null. SalesTable records are extracted correctly because I get inside the loop. Can you help me please?

  • dark_knight Profile Picture
    795 on at
    RE: parameter is not passed correctly to the class

    Hello Hossein,

    I use macro:)) The issue was related to the table buffer itself. When I passed salesId instead of the table buffer everything worked fine. I didn't change anything else. Described this in the post above. Anyway thanks.

  • Suggested answer
    Hossein.K Profile Picture
    6,646 on at
    RE: parameter is not passed correctly to the class

    Hi Azat,

    you should use macro to prevent this error.

    #DEFINE.CurrentVersion(3)
    #LOCALMACRO.CurrentList
    your parameter...
    #ENDMACRO

    in the pack method

    public container pack()
    {
        return [#CurrentVersion,#CurrentList,super()];
    }

  • dark_knight Profile Picture
    795 on at
    RE: parameter is not passed correctly to the class

    Resolved the issue. If someone's curious the issue was - you can't pack table buffer without any preparation. I just passed salesId instead:

    salesResrveForMultiThread.parmsalesId(salesTable.salesId);

    and everything worked fine.

  • dark_knight Profile Picture
    795 on at
    RE: parameter is not passed correctly to the class

    Did as you said. When I schedule it as a batch using menuitem then I get the same error. When I untick "batch" option runtimetasks are created and not bound to the main batch because it isn't created and they just get stuck. The main LauncherClass and it's runtimetasks are all executed on the AOS server tier.

    If you have any doubtful methods, I recommend you to check it. - Sorry but again I don't get it. All methods are executed on AOS server tier and it can't be different. When I execute classes on the client tier everything works fine. Also pack() and unpack() method look fine.

  • ergun sahin Profile Picture
    8,816 Moderator on at
    RE: parameter is not passed correctly to the class

    If the entire structure is running on the server or client, the situation I mentioned will not occur, but if there are changeovers, you may lose the value. If you have any doubtfull methods, I recommend you to check it.

    Can you try to make a menuItem (runOnServer) to the Class and run it?

  • dark_knight Profile Picture
    795 on at
    RE: parameter is not passed correctly to the class

    The main class and class which is executed as runtimetask are both executed on the same AOS server. I checked it in BatchHistory Journal.

    As I get it , when I launch class as a batch parameters are packed and everything is executed at AOS server side. Parameters are unpacked before that.

    so you can simply add isRunningOnServer() to the methods and see which side they are working on. - I don't get the point. If I put this method to each method when I debug on client it'll return false. Otherwise true. But I can't debug batches. So again I don't see the point.

    pack() and unpack() methods of my class salesResrveForMultiThread which is launched as a runtimetask above

    public container pack()
    {
        return [#CurrentVersion,#CurrentList];
    }
    
    public boolean unpack(container packedClass)
    {
        Version version = RunBase::getVersion(packedClass);
    ;
        switch (version)
        {
            case #CurrentVersion:
                [version,#CurrentList] = packedClass;
                break;
            default:
                return false;
        }
    
        return true;
    }

    and #currentlist and #currentversion macros:

    class SalesResrveForMultiThread extends runbasebatch
    {
        SalesTable  salesTable;
    
        #define.CurrentVersion(1)
    
        #localmacro.CurrentList
            salesTable
        #endmacro
    }

  • Suggested answer
    ergun sahin Profile Picture
    8,816 Moderator on at
    RE: parameter is not passed correctly to the class

    it's easier to examine the moment when the table goes to null in debug, but you may have trouble debugging in batches, so you can simply add isRunningOnServer() to the methods and see which side they are working on.

    As for why I'm asking, if there is a client/server side difference in batch and manual work, it means you have a pack/unpack problem.

    In a second possibility, if there is more than one AOS, you may be working on a different server from batch (CIL etc. may be problemic)

  • dark_knight Profile Picture
    795 on at
    RE: parameter is not passed correctly to the class

    Can you pls explain in more details? How should I do that?

  • Suggested answer
    ergun sahin Profile Picture
    8,816 Moderator on at
    RE: parameter is not passed correctly to the class

    Can you add client/server side controls to the code and see if there are changeover?

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