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 :
Microsoft Dynamics AX (Archived)

Dynamic Form and Button Questions

(0) ShareShare
ReportReport
Posted on by

So I'm trying to build a form dynamically and use a ListView to display data.  I want to be able to grab the selections that the user selects when the button is pressed.  Those values are then used to passed to the place where the form was called and used to write the method for the function.  Meaning, this doesn't go in the AX front end and is used in the backend for helping programmers quickly build methods.  The form builds, the ListView appears and is populated correctly and the button appears.  However, I can't get the button to work.  I've tried different types of buttons and the way it is now at least when the button is clicked it does absolutely nothing.  I do have a method defined:

void xButton_clicked()

{

   info("button clicked");

}

This is the init() method of the form.  Again, it's a dynamic form that populates the ListView based on the elements of an array that are passed to it.

public void init()

{

   Form                    xform;

   FormRun                 xformRun;

   FormBuildDesign         xdesign;

   FormBuildListControl    xlistView;

   FormBuildGroupControl   xlistGroup;

   FormFunctionButtonControl  xokButton;

   FormBuildButtonControl  xcancelButton;

   FormListControl         xlistControl;

   FormListItem            xlistItem;

   int                     xlistId;

   int                     xi;

   Args                    xargs;

   int                     xarrayLength = xfields.lastIndex();

   int                     xitemCounter;

   int                     xformWidth = 300;

   int                     xoffset = 30;

   //build the form using standard strategy:

   //form -> design -> group -> controls -> run

   xform = new Form();

   xform.name("FindMethod Field Select");

   xdesign = xform.addDesign('design');

   xdesign.caption("Form Generated from Form");

   xdesign.width(xformWidth);

   xdesign.statusBarStyle(1);//gets rid of bottom record navigation

   xlistGroup = xdesign.addControl(FormControlType::Group, 'Group1');

   xlistGroup.addControl(FormControlType::Group, "Group");

   xlistGroup.caption("List of Field Names");

   xlistGroup.width(xformWidth - xoffset);

   xlistGroup.heightMode(1);

   xlistView = xlistGroup.addControl(FormControlType::ListView, "List");

   xlistId = xlistView.id();

   xlistView.singleSelection(false);//allows the use of CTRL or SHIFT when making selections

   xokButton = xdesign.addControl(FormControlType::Button, 'xButton');

   xokButton.text("OK");

   xokButton.width(100);

   xokButton.height(30);

   //store the newly created form for use at runtime

   xargs = new Args();

   xargs.object(xform);

   //create the form at runtime

   xformRun = classFactory.formRunClass(xargs);

   xformRun.run();

   xformRun.detach();

   //setup the listview

   xlistControl = xformRun.control(xlistView.id());

   xlistControl.viewType(FormListViewType::Report);

   xlistControl.heightMode(1);

   xlistControl.addColumn(1, new FormListColumn("Field Name", 1, 250));

   xlistControl.widthMode(FormWidth::ColumnWidth);

   xlistControl.rowSelect(true);

   //populate the listview by looping through the array of field names

   for(xi = 1; xi <= xarrayLength; xi++)

   {

       xlistItem = new FormListItem(xfields.value(xi));

       xitemCounter = xlistControl.addItem(xlistItem);

   }

   super();

}

And the run() method:

public void run()

{

   element.controlMethodOverload(true);

   super();

}

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    I believe the problem is that you call controlMethodOverload() on element, but the button has been added to xformRun, which is a new form independent on element.

    I would also say that you complicate your life more than it's necessary. If you know that you'll need a ListView and a Button (with click() handler), you don't need to generate them at all, you can simply add them to an AOT form. Add dynamically only such things that are not known at design time.

  • Community Member Profile Picture
    on at

    Thanks.  You actually were absolutely correct.  I definitely over complicated it.  You pointed me in the right direction.

  • Suggested answer
    Deepak Agarwal Profile Picture
    8,602 on at

    hi,

    check this link

    theaxapta.blogspot.in/.../list-view-control-in-dynamics-ax.html

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans