Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

FormDataSource - AllowEdit()

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi Community,

following Scenario:

I have a table with two fields: firstname and lastname.

I made a form for it, set the DataSource in the Design to "Table5" (tablename) and dragged the fields...

In the Code (Screenshot) I set that my firstname shall not be edited, but in the form or table it still can be edited!

What is the Problem with my code ? or did I place the code not correctly ? I wrote the code in the Forms Method.

4426.forCommunity.PNG

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: FormDataSource - AllowEdit()

    Amazing, thanks to both of You.

    Unfortunately I wasn't Aware of "element". I tried it with "this" and I tried several other Things ........................... but nothing worked.

  • Verified answer
    startax Profile Picture
    startax 1,845 on at
    RE: FormDataSource - AllowEdit()

    HI

    As ievgen Miroshnikov suggested you can create new method allowEditFirstName() and write your code to allow edit false.

    public int active()

    {

       int ret = super();

       element.allowEditFirstName();

       return ret;

    }

    Or you can directly write

    public int active()

    {

       int ret = super();

       table_ds.object(fieldnum(table, field1)).allowedit(false);

       return ret;

    }

  • Verified answer
    Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: FormDataSource - AllowEdit()

    I'm not quite sure why do you have a problem here. Just type element.allowEditFirstName(); after super() in active method of form data source, something like:

    public int active()

    {

       int ret = super();

       element.allowEditFirstName();

       return ret;

    }

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: FormDataSource - AllowEdit()

    For now I am lacking in the Code.

    I want to overwrite my active() ad call allowEditFirstName, but I am lacking.

    I can't call it with this.allowEditFirstName.´

    I have to do more.

    I Need a Connection to the Form which I called "Form5".

    I just Need to find a way how to call the method which I wrote in Form5.

    Do You have a good tip on how I can call the allowEditFirstName() in the active() ?

  • Jie G Profile Picture
    Jie G on at
    RE: FormDataSource - AllowEdit()

    You need to call your code to disable editing during form's built-in methods. You can check the inheritance of FormRun to get more details.

  • Suggested answer
    Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: FormDataSource - AllowEdit()

    Your method will disable the field. "allowEdit" is quite a generic name, I would rename it to "allowEditFIrstName".

    You have to override  active() method and call your method there, AX will call active() for you whenever user select a record in a grid, so don't worry about calling active() manually.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: FormDataSource - AllowEdit()

    Ok I will do it.

    Then, my allowEdit() is right ?

    You said "You can add a call to active() of the form datasource" , where do I make that call ?

    I don't have to override my active() I guess, but do I have to make a new Method in the

    Table5 DataSource, where I call the active() ?

  • Suggested answer
    Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: FormDataSource - AllowEdit()

    Hi Khashayar G ,

    If you want to disable edit on this field permanently, set property "AllowEdit" and "AllowEditOnCreate" to "No" on the Table field itself.

    If you want to do it in the runtime via code then you need to call your new "allowEdit" method, because AX won't call it for you. You can add a call to active() method of the form datasource, it is called by AX each time you highlight a record in a grid or you can add it to init() method, that is called only one, when you open the form.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,074 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,900 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans