modify allow edit property on table level

How to modify allow edit property on table level using X++ code?

Property of what? A datasource? A field? An unbound control? Or something else?

What do you mean by “on table level”?

You’ll have a better chance to get a solution if you give us a more detailed explanation of your problem.

By the way, you forgot to attach a tag with your version of AX, so we don’t know whether you’re talking about Axapta 2.5, AX 7 or what. Please fix it.

How to write code to modify table’s allow edit and mandatory property on table’s method. (ax 2012 r2)

Please pay attention to what you say. Tables don’t have such properties, therefore I guess you meant field properties.

Properties on tables and tables fields in AOT are defined at design time and you shouldn’t try ti change them at runtime.

What you can do, though, is changing properties of form datasource fields. If you want, you can do it in a table method, if you pass a reference to the datasource field object.

It’s usually done directly in a form and it looks like this:

boolean canBeEdited = …
MyTable_ds.object(fieldNum(MyTable, MyField)).allowEdit(canBeEdited);

Thanks Martin… Consider one situation where table field’s mandatory property is set to yes and I modified its mandatory property to no on datasource’s field it will still ask me to enter data because mandatory property is set to table’s field (ax 2012 r2)

Yes, that’s the correct behavior. If the field is designed to always require a value, providing an empty value would cause a data inconsistency. It would be a bug.

If you say that the field isn’t always mandatory, set it as optional at table level and handle those cases where a value is required.

Thanks a lot Martin

You refer me code :

boolean canBeEdited = MyTable_ds.object(fieldNum(MyTable, MyField)).allowEdit(canBeEdited);

but I am not able to write code on tables method with mytable_ds. mytable_ds can be written on form datasource method

Your code is wrong - it doesn’t make sense and you’re even trying to use a variable that you’re declaring only in the same statement.

Yes, this must be used in the form. If you want to use the object in a table method, you must pass it there as a parameter. E.g.:

FormDataObject o = MyTable_ds.object(fieldNum(MyTable, MyField));
someTableBuffer.someMethod( o );

You always need a reference to the object you want to manipulate.