How to make a single record non editable


actualy i need only one field in single record to non editable…but by using this code this fiels in all record is getting non editable

i mean i need record level access in tabular form

If you use CurrForm.EDITABLE(FALSE) then it changes all the fields on the form to be non editable.

If you use CurrForm.YourField.EDITABLE(FALSE) then it only changes the field YourField to be non editable.

If it’s only a specific record that must be non editable, then you need to check if it’s the right record before setting the EDITABLE property:

IF FieldXX = FieldXX::ThisOptionMeansNonEditable THEN CurrForm.YourField.EDITABLE(FALSE);

Or shorter:

CurrForm.YourField.EDITABLE(FieldXX <> FieldXX::ThisOptionMeansNonEditable);

Thomas, you’re right. I usually do it that way also, but many new NAV developers is not familiar with this way of writing code. I bet you have also see “bad” code like this:

IF BooleanVariable = TRUE THEN DoSomething;

I think if you never have learned to program in Pascal, then the C/AL is very different from other programming languages.

I know, depending on the time of the day I’m using both versions.

Anyway you would need an “else” which sets the field back to editable(TRUE), otherwise the field switches to readonly as soon as the condition is met and never back on again.

I did not want to say that your code is wrong, but if the “newbies” do never see both ways, they will not learn it.

I even found a better one:

IF NOT (BooleanVariable = TRUE) THEN DoSomething;

I like to move it, move it !!!

This is getting philosophical. What code is wrong? It depends so much on how it was taught, what a code snippet looked like in your early days, what looks to an individual programmer. In the end, if it gets the job done, there are many ways to get the job done.

I don’t have any formal education for programming, other than a 3 month course in college. My teacher taught me that “IF SomeVariable <> SomeValue” is a bad way to program because the system has to evaluate it in multiple steps to evaluate the expression, and he said that it would be better to program “IF NOT (SomeVariable = SomeValue)”. I don’t know if he was right or not (it is probably even different for different languages), but it is still how I program, it is why I always include a full expression (even when working with boolean variables), and it is why I always put parentheses around the expression, just to be explicit in my intention. I always try to make the first leg of an IF statement be the ‘positive’ pole and the ELSE leg be the negative. So instead of “IF SomeVariable <> SomeValue THEN DoX ELSE DoY” I would do “IF (SomeVariable = SomeValue) THEN DoY ELSE DoX”, or “IF NOT (SomeVariable = SomeValue) THEN DoX ELSE DoY”. I like using NOT and the equal sign instead of <> because in my opinion it makes it easier to read the intention, rather than trying to come to terms with double negatives. Then again, in that case I would probably switch the legs of the IF statement around :slight_smile:

It does not really matter how one programs and this is not a discussion about good style within logical expressions and if the IF or ELSE should be the positive leg.

2 things are important:

1st. the code must work (preferably in a kind of optimized way to speed up the system as far as possible)
2nd. the code should be readable

There are (as always) several ways to hit the target you are aiming for.
I see it as our task to show all (or most of) the ways to the “newbies” to let them decide which one they would prefer. As most of the new Navision developers have done development with other languages before - they most probably already have their own “personal” style.

And last but not least, Eriks statement was just incomplete and would cause problems with editing records AFTER a non-editable record has been shown as the ELSE leg was missing which re-enables the control.

This is really nice, but I think beating all would be combining the circumstantial with the superfluous… - perhaps like this:

IF NOT (BooleanVariable <> TRUE) THEN
BooleanVariable := TRUE;

To get a textbox within a tablebox non editable for only a single (or some special) records you have to put the following code (proposed already by other users above in the same or in a similar form) into the OnAfterGetCurrRecord Trigger of the tabular form:

CurrForm.myField.EDITABLE(myPrimaryKey <> mySpecialValue);

For example, if you have an editable list form for Customers and you want the Name for Customer with “No.” 30000 not to be editable the code would be:

CurrForm.Name.EDITABLE(“No.” <> ‘30000’);

Of course, you can use other conditions depending on arbitrary fields to decide, whether the field should be editable or not…