Does anyone know if it is possible to restrict the access to a field and not to the entire table?
For example: Only user 'x' have access to all fields of the table, the others cannot have access to one of the fields of this table.
Function Variables:
FieldsRec - Record (Table from step 1)
xRecRef - RecordRef
FieldRef - FieldRef
xFieldRef - FieldRef
Code:
xRecRef.GET(RecRef.RECORDID);
FieldsRec.RESET;
FieldsRec.SETRANGE("User ID", USERID);
FieldsRec.SETRANGE("Table ID", RecRef.NUMBER);
IF FieldsRec.FINDSET THEN
REPEAT
FieldRef := RecRef.FIELD(FieldsRec."Field ID");
xFieldRef := xRecRef.FIELD(FieldsRec."Field ID");
IF FieldRef.VALUE <> xFieldRуf.VALUE THEN
ERROR('You do not have permission to change the field');
UNTIL FieldsRec.NEXT = 0;
Answers
But the restriction on the reading of the field cannot be realized even with the modification.
If necessary I can describe the implementation in NAV 2017
1. Create Table for restricted fields. Table Fields:
User ID - Code(50)
Table ID - integer
Field ID - integer
Key - User ID, Table ID, Field ID
2. create subscription function. Event - Subscriber, EventPublisherObject - Codeunit ApplicationManagement, EventFunction - OnAfterOnDatabaseModify.
Function Parameters:
VAR RecRef - RecordRef
Function Variables:
FieldsRec - Record (Table from step 1)
xRecRef - RecordRef
FieldRef - FieldRef
xFieldRef - FieldRef
Code:
xRecRef.GET(RecRef.RECORDID);
FieldsRec.RESET;
FieldsRec.SETRANGE("User ID", USERID);
FieldsRec.SETRANGE("Table ID", RecRef.NUMBER);
IF FieldsRec.FINDSET THEN
REPEAT
FieldRef := RecRef.FIELD(FieldsRec."Field ID");
xFieldRef := xRecRef.FIELD(FieldsRec."Field ID");
IF FieldRef.VALUE <> xFieldRуf.VALUE THEN
ERROR('You do not have permission to change the field');
UNTIL FieldsRec.NEXT = 0;