0

In Business Central it's possible to make something like that:

}   
    field(5; "From"; Integer)
    {
         Caption = 'From';
         DataClassification = SystemMetadata;
         Editable = FromEditbale
    }
}

var
FromEditable: Boolean

So my Question is, if something like this could work. Because I tried it several Times, but it seems like it rejects the Global Integer Variable. Any ideas why or do you know, what I'm doing wrong?

}   
    field(5; "From"; Integer)
    {
         Caption = 'From';
         DataClassification = SystemMetadata;
         MaxValue = ToValue
    }
}

var
ToValue: Integer
Ozea
  • 13
  • 2

2 Answers2

0

That is really depends on the field. For 'editable' you can use variable, for 'maxvalue' you can't.

Mak Sim
  • 2,148
  • 19
  • 30
0

Table properties must be set as literals which means you cannot use variables as the source expression (i.e. both of your examples aren't possible).

The solution available to you really depends on the scenario.

You could handle it using the OnValidate trigger:

field(5; "From"; Integer)
{
     Caption = 'From';
     DataClassification = SystemMetadata;

     trigger OnValidate()
     begin
         if Rec.From > MyMaxValue then
             Rec.FieldError(Type, ...);
     end;
}

var
    MyMaxValue: Decimal

Or you could handle it at page level where variables can be used as source expression:

field(From; From)
{
    MaxValue = MyMaxValue;
}

var
    MyMaxValue: Decimal

Keep in mind that no matter which solution you choose it would still be possible to assign a value higher than your defined maximum through assignment:

Rec.From := 999999; // Would not generate an error if MaxValue was e.g. 10000
kaspermoerch
  • 16,127
  • 4
  • 44
  • 67