Create Display / Edit Rule

Estimated reading: 3 minutes

Display rules and edit rules can be entered in the general Table Settings (Fig. 1) and in the Table Rights of user groups (Fig. 2). If you want to set the edit rule in the general table settings go to the table the rule is for and click on the

symbol. If you set a rule here it is a general rule for all user groups.

A Display rule has the effect that a certain record or a table is only shown in the record view if the rule is fulfilled. However the record or the table can be edited in the background by a script, a limbas function. On the other side if the rule is an edit rule the record or the table can only be edited if the rule is fulfilled. Then also a background skript can’t edit the record or the table.

Fig.1: insert view or edit rule in the general table settings

The behavior is controlled by the ‘return value’ of the function:

  • false: No change applied. Behavior as if no rule assigned. The table or the table field is displayed and can be edited.
  • true: The table or the table field does not appear and can’t be edited.

The functions to be called can be implemented in ext_gtab.inc.

The following variables can be used in the function call:

  • $ID: record ID
  • $gresult[]: Array with ‘return result’ of the last database access. Could be the contents of the entire table or a data record.
  • $gtabid: Table ID of the currently displayed table
  • $key: Table field ID of the table field to be validated
  • $fieldid: field ID
Fig.2: possibilities where to paste an edit rule in the table rights of the user group

The source code for the examples is written in EXTENSIONS/CRM/ext_gtab.inc.

If this function, for a table ‘Date’ field, is entered in the display rule as below, it appears in the Record View and Edit Mode only if the date entered is prior to the year 2000:

return extShowDateBeforeYear($ID, $gtabid, $key, $gresult, 2000);

In the demo application the example is built in the table payment.

If this function, in the table rights of a user group, is entered as a rule for ‘write right’, this user group can edit the table only on a Friday:

return extShowOnlyOnWeekday("Friday");

This line must be inserted in one of the opened fields in fig. 2. The field on the top left affects the whole table the field right down affects only the individual record. In the demo application the example is set for the user group admin in the table positions.