Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Problem with getting args().record()

(0) ShareShare
ReportReport
Posted on by 781

Hello,

I created a form that has InventTrans as the main datasource. From this form, I run the standard ProdTableCreate form :)

The requirement is that the ProdTableCreate form, when opened, is already populated with values from the selected line from the InventTrans form. Everything works OK, the form is populated with values, it creates a production order, but I always get the well-known error "Object reference not set to an instance of an object." at the end of steps.

I did some debugging and the error appears in the standard refreshCaller method at common_ds.research(). When executing the method, the common_ds variable has the null value..
Can anyone suggest what I am doing wrong?

standard refreshcaller() method:

 void refreshCaller()
    {
        Common         common;
        Common         commonDim;
        FormDataSource common_ds;
        FormDataSource commonDim_ds;

        if (element.args().dataset() == tableNum(SalesLine))
        {
            common      = element.args().record();
            common_ds   = FormDataUtil::getFormDataSource(common);

            common_ds.reread();
            common_ds.refresh();

            commonDim       = common.joinChild();

            if (commonDim.TableId == tableNum(InventDim))
            {
                commonDim_ds    = FormDataUtil::getFormDataSource(commonDim);

                commonDim.data(InventDim::find(prodTable.InventDimId));
                commonDim_ds.setCurrent();
            }
        }
        else if ( element.args().record() )
        {
            common_ds   = FormDataUtil::getFormDataSource(element.args().record());
            common_ds.research();
        }

init() method extension:

 public void init()
    {
        
        InventMovement  callerMovement;
        Object          callerFormObject;
        ProdTable       prodTableLocal;
        ProdIProdTableDefaultValuesProvider prodTableDefaultValuesProvider;

        next init();
  
        if (this.args() && this.args().caller())
        {
            callerFormObject = this.args().caller();

            switch (this.args().dataset())
            {
                case (tablenum(InventTrans))   :
                    callerBuffer = this.args().record();
                    break;

                default:
            }
        }
    }

refreshCaller() method extension:

  void refreshCaller()
    {
        Common         common;
        Common         commonDim;
        FormDataSource common_ds;
        FormDataSource commonDim_ds;

        if (this.args().dataset() == tableNum(InventTrans))
        {
            common      = this.args().record();
            common_ds   = FormDataUtil::getFormDataSource(common);

            common_ds.reread();
            common_ds.refresh();

            commonDim       = common.joinChild();

            if (commonDim.TableId == tableNum(InventDim))
            {
                commonDim_ds    = FormDataUtil::getFormDataSource(commonDim);

                commonDim.data(InventDim::find(prodTable.InventDimId));
                commonDim_ds.setCurrent();
            }
        }   

        next refreshCaller();
    }

  • Martin Dráb Profile Picture
    232,930 Most Valuable Professional on at
    RE: Problem with getting args().record()

    Well, you can keep speculating or start analyzing the situation. I would do the latter. Even if you think that there should be a record in the 'common' variable, there is a huge difference between thinking and knowing for sure.

  • Shooowtek Profile Picture
    781 on at
    RE: Problem with getting args().record()

    I don't really understand.

    In the variable 'common' should be the actual args().record() from the caller form source.

    If I run the ProdTableCreate form, from a form with InventTrans source, should there be an actual passed record in args().record(), which is then passed to the 'common' variable?

    I don't understand why in my method extension I could pass args().record() to the variable 'callerBuffer' , but in the refreshCaller() method it doesn't work to the variable 'common'?

  • Martin Dráb Profile Picture
    232,930 Most Valuable Professional on at
    RE: Problem with getting args().record()

    OK, so the record isn't associated with a form data source. Do you have any record at all (in 'common' variable)?

  • Shooowtek Profile Picture
    781 on at
    RE: Problem with getting args().record()
    [quote]

    Which line of code is throwing the error?

    [/quote]

    7266.error.png

  • Martin Dráb Profile Picture
    232,930 Most Valuable Professional on at
    RE: Problem with getting args().record()

    Which line of code is throwing 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,157 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,930 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans