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.
*This post is locked for comments
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.
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;
}
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;
}
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() ?
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.
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.
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() ?
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.
André Arnaud de Cal...
292,074
Super User 2025 Season 1
Martin Dráb
230,900
Most Valuable Professional
nmaenpaa
101,156