Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

How to get Access to UI controls from X++

Posted on by Microsoft Employee

Hello for everyone,

How can I get access to UI controls (Buttons, ComboBox, Checkbox, etc) from X++. I want programmatically change statements for these elements and can't find detail instruction for this. Anyone can help me?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to get Access to UI controls from X++

    I don't know how to describe a business requirement for this issue.  I think a business requirement didn't complete. I have to have a long discussion with the user for more details. At this moment I have only technical interpretation and unclear business requirement, but the technical solution was found.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to get Access to UI controls from X++

    This solution was useful in my case.  This is not a direct answer to my question, but it helps me solve a problem.

  • nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: How to get Access to UI controls from X++

    Hi Anton, do you still have some open questions? If not, could you please mark the helpful answer(s) as verified. Thanks!

  • nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: How to get Access to UI controls from X++

    Your previous description is definetely not a business requirement, it's some kind of a technical interpretation of it. I'm sure your customer did not ask you to do that, instead they have some natural language description on what the user should be able to do and see in the system. And knowing that requirement would help me help you better.

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: How to get Access to UI controls from X++

    Is this something that should happen real time between the two forms? Or is your checkbox more like a parameter that should control the allowEdit property across the system, for all users (not only on currently opened form for the current user)?

    If former, please check this discussion, it shows how you can call code of Form2 from Form1. But you must open Form1 with a button from Form2 or otherwise you don't have any handle that would allow you to do it. You can only call methods of forms if you have a handle to the active instance of the form.

    dynamicsuser.net/.../calling-method-on-a-caller-form

    If latter, your init method of Form2 should check the value of the checkbox from the database, and set the allowEdit of the field to yes/no accordingly.

    I'm still not sure if I understand your question, though. Could you share your business requirement?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to get Access to UI controls from X++

    My business requirement is:

    The Form::Form1 contains the Combobox::combo_select. When a user in the combobox selects specific item in the Form::Form2 the algorithm has to change Checkbox::Deprication.AlowEdit = false

    Form1: AOT/Forms/Form::Form1

    Combobox: AOT/Forms/Form::Form1/Designs/Design/TabPage::Tab2/Group::Group6/Combobox::combo_select

    Form2: AOT/Forms/Form::Form2

    Checkbox::Deprication: AOT/Forms/Form::Form2/Design/TabPage::Tab2/Group::Group1/Checkbox::Deprication

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: How to get Access to UI controls from X++

    No, you can't access the control from outside the form. Or, you can, if you have handle to the formRun instance, but you don't have that in the validateWrite method of that table. And that's definetely a wrong place for your code.

    You need to understand that you want to change the property for one instance of the form, in runtime. Not in the AOT definition of the form. Otherwise you would be doing development (metadata) changes in a live system for all users every time the validateWrite of the table was triggered. I'm sure that's not what you intend to do, right?

    Could you share your business requirement?

    If you want to change the form controls at runtime, you need to write your code in the form. For example in the validateField method of the form data source. The validataWrite of the table doesn't know anything about your form, and the formRun is not in the scope for the validateWrite method.

    Except, I don't think you should use validateField for that, since that method is intended for validating data, not manipulating the UI. But since I don't know your business requirement, I can't propose any exact solution for you.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to get Access to UI controls from X++

    I set AutoDeclaration  of Checkbox to Yes.

    For example:

    My table name is RAssetStandarts. The form resides AOT/Forms.

    AOT/Forms/Forms::RAssetStandarts/Designs/Design/TabPage::General/Group::DepricationGroup/CheckBox::Deprication

    I find this object in AOT but I don't know how to change properties of CheckBox via X++

    I want to get access to this field from AOT/Data Dictionary/Tables/RAssetTable/valdateField
    validateField is a source file.

  • Verified answer
    nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: How to get Access to UI controls from X++

    So, you have a control of name Checkbox.

    1. Set AutoDeclaration of your Checkbox to Yes

    2. In x++ code: Checkbox.allowEdit(false) .

    Like I wrote, you can use the control name directly in code, so I don't understand how you "don't know how to navigate to this element via x++". Could you give more information?

    Also, if your checkbox is actually bound to a field in the data source, you can also use:

    MyTable_ds.object(fieldNum(MyTable, MyField)).allowEdit(false);
  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to get Access to UI controls from X++

    I try to set the properties for CheckBox.AlowEdit  = false for specific form. I don't know to get access to specific CheckBox and properties for it. I know specific Name of form. I know Name of specific CheckBox but I don't know how to navigate to this element via X++.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,459 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,783 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans