web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

How to assign a value to a real type form control

(0) ShareShare
ReportReport
Posted on by 6,470

Hello,

On an extension of Form I have added a Real type control to the form, where I want to assign the number of currently selected lines from grid.

I have created a class and copied the "OnActivated" event of the main datasource. There I have placed the below code:

[FormDataSourceEventHandler(formDataSourceStr(ReqTransPo, ReqPo), FormDataSourceEventType::Activated)]
    public static void ReqPo_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
    {
        FormRun formRun = sender.formRun() as FormRun;
        
        FormRealControl numOfLinesControl = formRun.design().controlName(formControlStr(ReqTransPo, NumOfLinesXX)) as FormRealControl;
        numOfLinesControl.realValue(sender.recordsMarked().lastIndex());
    }

When I open the form it gives the error message "Object reference not set to an instance of an object." 

What do I need to change?

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: How to assign a value to a real type form control

    You should be able to find plenty of examples if you search the web for "dynamics ax (or 365 operations) get number of selected records on grid".

  • Johnny Profile Picture
    6,470 on at
    RE: How to assign a value to a real type form control

    Not sure what was happening. I did the full build of extension model and it's working now.

    But it is working when I select the lines one by one. If I click the "thing" (don't know how it is called) which selects all the lines in the grid the value of my field isn't updated.

    Which event should I possible use to get the number of all lines if I click "select all lines" thing on grid?

  • nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: How to assign a value to a real type form control

    I think debugging already helped a great deal. Now we know that the issue is in accessing the real control. And not something in line 7, and definetely not in assigning a value to a real control. Perhaps you already knew it but we didn't.

    Are you sure that NumOfLinesXX a real control, and not an integer?

  • Johnny Profile Picture
    6,470 on at
    RE: How to assign a value to a real type form control

    I have re-written the line like:

    FormRealControl numOfLinesControl = formRun.control(formRun.controlId(formControlStr(ReqTransPo, NumOfLinesXX))) as FormRealControl;

    But it still getting NULL.

    The control Auto Declaration property is set to Yes

  • Johnny Profile Picture
    6,470 on at
    RE: How to assign a value to a real type form control

    Yes, it returns null on line 6. Debugging will not really help here, that's why I asked a question here to get an answer how to correctly initialize my FormRealControl.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: How to assign a value to a real type form control

    You can assign it by MyControlName.realValue(myRealValue);

    So, your problem is not "how to assign a value to a real type form control". Instead you are trying to call a method on a null object.

    You must debug your code to find the issue.

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

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

#2
Sohaib Cheema Profile Picture

Sohaib Cheema 850 User Group Leader

#3
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 827

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans