How Do I Prevent the End User from Modifying Any Record in a Task? (Magic xpa 4.x)
By default, when you create an online task in Magic xpa, the task allows the user to do anything to a record: add, delete, and modify. The data source is opened in write mode, and records are locked if they are modified.
This is very useful for creating quick programs to maintain tables. However, in most applications, users are restricted from modifying certain records, and many screens will be for display only and you don’t want to accidentally modify or lock records.
There are several levels of control you have over modification of data in Magic xpa. They are listed here.
Setting the Access property of the data source is the most foolproof way to ensure the record does not get modified. If you do happen to accidentally modify a record that is opened in Read, then you will get a DB error, but the record won’t be changed. The table will also open faster if it is opened in Read, so it is a good practice for tasks that are not supposed to update data.
Setting the Initial Mode in Task Properties to Query will cause the task to be opened in a non-modifiable mode. This is the mode you want for “lookup” or “view only” tasks.
However, the user can still change the mode from Query to Modify by selecting Options->Modify Records (Ctrl+M), unless you prevent that by also setting Task Properties->Options->Allow Options to No, as shown in the frame on the right.
The Task Properties (Ctrl+P) option gives you more specific control over what is allowed in this task. Each option can be set to Yes or No, or you can enter an expression which will determine whether or not that particular function is allowed, on a user-by-user or record-by-record basis.
For instance, in this case we never allow the user to delete a record on this task. But we do allow the user to modify a record if the order date is less than 30 days old.
In addition to the data source level control, you also have control at the field level.
You can prevent the user from parking on a field by setting Allow Parking to No in the Control Properties.
You can allow the user to park on a field but not modify it, using the control’s Modifiable property. This can be set to Yes or No, or to an expression if you need Boolean logic.
The Online and Rich Client Samples projects (program EN08 and REN08)