SetFieldProtection()

Summary

Changes the read-only status of a field.

Syntax

SetFieldProtection(string field_spec, boolean protection_flag)

Argument Contents
field_spec An input field
protection_flag The new read-only status of the field

Notes

  • If a field is protected, the user cannot change its value in an editor. Other operations in Caliper Script, like SetRecordValues(), can still change its value.

  • Some fields are always read-only, and their status cannot be changed by the SetFieldProtection() function. These include the linking fields in a joined view (see JoinViews() and JoinViewsMulti()), any aggregation fields (see SelfAggregate() , JoinViews() and JoinViewsMulti()), any expression fields (see CreateExpression()), and any field on a view that is read-only (see GetViewReadOnly()).

  • If the SetFieldProtection() function succeeds, the change status is propagated to all joined views containing this field. If the input field itself belongs to a joined view, the change is also propagated to any underlying base views.

Example

SetFieldProtection("Employee.Salary", "True") // Salary cannot be changed
SetFieldProtection("Employee.Address","False") // Address can be edited

Error Codes

Error Type Meaning
Error The field cannot be set to the specified status, e.g., if the field is the link field in a joined view and the input protection_flag is "False"
NotFound The input field does not exist or the field specification is ambiguous

See Also

Function Summary
GetFieldProtection() Gets a string that indicates whether a field is read-only
GetViewReadOnly() Reports whether a view is read-only
SetViewReadOnly() Changes the read-only status of a view