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)

FormDataSource - AllowEdit()

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Suggested answer
    Mea_ Profile Picture
    60,284 on at

    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.

  • Community Member Profile Picture
    on at

    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
    60,284 on at

    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.

  • Jie G Profile Picture
    on at

    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.

  • Community Member Profile Picture
    on at

    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() ?

  • Verified answer
    Mea_ Profile Picture
    60,284 on at

    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;

    }

  • Verified answer
    startax Profile Picture
    1,845 on at

    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;

    }

  • Community Member Profile Picture
    on at

    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.

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