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)
Answered

How to get Access to UI controls from X++

(0) ShareShare
ReportReport
Posted on by

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?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    Set AutoDeclaration to Yes in the properties of the control. Then use the control name in your code to access it.

  • Community Member Profile Picture
    on at

    Thank you for your answer. But  where can I find 'properties of the control'?

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

    They can be found as methods of the object.

    Just type [MyControlaName]. and see what you get.

    If you still need help, could you tell us a bit more what you are trying to achieve. Thanks!

  • Community Member Profile Picture
    on at

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

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

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

    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.

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

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

    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
    101,160 Moderator on at

    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?

  • nmaenpaa Profile Picture
    101,160 Moderator on at

    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.

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