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

How to assign a value to a real type form control

(0) ShareShare
ReportReport
Posted on by 6,478

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

    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.

  • Johnny Profile Picture
    6,478 on at

    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.

  • Johnny Profile Picture
    6,478 on at

    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

  • nmaenpaa Profile Picture
    101,160 Moderator on at

    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,478 on at

    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?

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    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".

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 592 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 305 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans