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

parameter is not passed correctly to the class

(0) ShareShare
ReportReport
Posted on by 942

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?

I have the same question (0)
  • Suggested answer
    ergun sahin Profile Picture
    8,826 Moderator on at

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

  • dark_knight Profile Picture
    942 on at

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

  • Suggested answer
    ergun sahin Profile Picture
    8,826 Moderator on at

    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
    942 on at

    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
    }

  • ergun sahin Profile Picture
    8,826 Moderator on at

    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
    942 on at

    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.

  • dark_knight Profile Picture
    942 on at

    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.

  • Suggested answer
    Hossein.K Profile Picture
    6,648 on at

    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
    942 on at

    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.

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
Martin Dráb Profile Picture

Martin Dráb 551 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans