Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

Add real field control dynamically in Form

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.
 
 
  • Martin Dráb Profile Picture
    Martin Dráb 230,214 Most Valuable Professional on at
    Add real field control dynamically in Form
    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.
  • Add real field control dynamically in Form
    @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
    Martin Dráb 230,214 Most Valuable Professional on at
    Add real field control dynamically in Form
    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").
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,605 Super User 2024 Season 1 on at
    Add real field control dynamically in Form
    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
    Martin Dráb 230,214 Most Valuable Professional on at
    Add real field control dynamically in Form
    It works correctly for me.
     
  • Martin Dráb Profile Picture
    Martin Dráb 230,214 Most Valuable Professional on at
    Add real field control dynamically in Form
    Moved from Dynamics AX forum.
  • Add real field control dynamically in Form
    yes, this code snippet is enought.
    D365 f&O(10.0.37 (10.0.1725.47))
  • Martin Dráb Profile Picture
    Martin Dráb 230,214 Most Valuable Professional on at
    Add real field control dynamically in Form
    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?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans