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

Add real field control dynamically in Form

(0) ShareShare
ReportReport
Posted on by 4
Hello!!
 
I have a requirement were I have to add multiple budget year (depending budget years specified on another form) and the respective budget values dynamically in a new custom form. When I try adding it using below code I get the control names on the form but respective budget value is missing. When I debug the code budget value is correctly inserted in the control but on the front end the values are not displayed. 
 
 public void run()
   {
      FormBuildDesign             formBuildDesign = form.design();
      FormBuildGroupControl       formBuildGroupControl;
      FormRealControl c;

      while (i <= countBudgetLine)
      {
         c = budgetyeargroup.addControl(FormControlType::Real, 'YearName' + int2str(i));
         c.label(conPeek(yearName,i));
         c.realvalue(conPeek(budgetAmountCon,i));
         c.registerOverrideMethod(methodStr(FormRealControl, validate), 'runTimeControlValidate');
         formBuildGroupControl = formBuildDesign.control(budgetyeargroup.id());
         i++;
      }
      super();
   }
 
Please suggest.
 
 
I have the same question (0)
  • Martin Dráb Profile Picture
    237,912 Most Valuable Professional on at
    It seems to me that that a half of your code isn't needed to demonstrate the problem. I'm would reduce it to this:
    public void run()
    {
        FormRealControl c = budgetYearGroup.addControl(FormControlType::Real, 'YearName1');
        c.label("TEST");
        c.realValue(999);
    
        super();
    }
    Do you agree?
     
    Which version of AX are you using?
  • Community member Profile Picture
    4 on at
    yes, this code snippet is enought.
    D365 f&O(10.0.37 (10.0.1725.47))
  • Martin Dráb Profile Picture
    237,912 Most Valuable Professional on at
    Moved from Dynamics AX forum.
  • Martin Dráb Profile Picture
    237,912 Most Valuable Professional on at
    It works correctly for me.
     
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at
    It depends based on elements found in the container. 
     
    c.realvalue(conPeek(budgetAmountCon,i));
     
    At this point, do you have values in the container "budgetAmountCon" specified? Firstly, try directly assigning some value like below. Also, you can remove validation part for now.
     
    c.realvalue(123);
     
    If this is working then check about container and then validation.
  • Martin Dráb Profile Picture
    237,912 Most Valuable Professional on at
    Akshata confirmed that this code can be used to test the problem:
    public void run()
    {
        FormRealControl c = budgetYearGroup.addControl(FormControlType::Real, 'YearName1');
        c.label("TEST");
        c.realValue(999);
    
        super();
    }
    There is container involved. That was in the original code, before we simplified it to be able to focus on the actual problem and without being distracted by unrelated code.
     
    If Akshata said that the simple code worked and the actual didn't, then we'd know that the control adding and value setting isn't the actual problem and we would check things like the container (despite Akshata's claim that "the code budget value is correctly inserted").
  • Community member Profile Picture
    4 on at
    @Martin: 
    My requirement is to add multiple controls in grid but here it gets displayed one after another 
     
    when I add the controls directly to design controls 
    c1= element.design().addControl(FormControlType::Real, 'YearName' + int2str(i));
    c1.label(conPeek(yearName,i));
    c1.realValue(conPeek(budgetAmountCon,i));
     
     
    I want controls to be printed in grid format which I am able to achieve by adding controls in groupControl but here values are not getting displayed.
     
     
    c = budgetyeargroup.addControl(FormControlType::Real, 'YearName' + int2str(i+6));
    c.label(conPeek(yearName,i));
    c.realValue(conPeek(budgetAmountCon,i));
     
    @Bharani: the containers have values and even after removing the validation values are not displayed on form.
  • Martin Dráb Profile Picture
    237,912 Most Valuable Professional on at
    It's great to hear that you're now able to successfully add real controls and set their values.
     
    You never mentioned a grid before and your approach indeed can't work a grid. Grid requires columns bound to field or method.Either don't use a grid, or forget all your current code, because you'll need to design a completely different solution.

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

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans