When using pre-planned structural prototypes, i.e. those stored apart from actual content and with no purpose other than as a means to configure other content notes, consideration should be given to whether action code such as found in in Action-type attributes is run in the prototype itself, or should be suppressed there and only run in a note inheriting from the prototype. This scenario affects code placed in the Action-type attributes (e.g. via their create/rename dialog boxes):
- $OnAdd
- $Rule
- $AgentAction (agents only)
- $DisplayExpression
- $TableExpression
In some cases it is desirable to delay code execution as the code is written with the intention of running in an inherited context, using actual data from the inheriting note. It is also desirable to delay where there is a need to run code once only but again, within an inherited note's context.
Two of the above attributes have special system attributes to suppress prototype execution. $DisplayExpressionDisabled and $RuleDisabled, then set to true, suppress the running of the note's $DisplayExpression or $Rule. In pre-v5.8.0 versions, or where using other Action-type attributes, employ the method outlined below.
Where no disablement attribute exists, consider wrapping the code in a conditional test. For example:
if(!$IsPrototype){$AgentQuery="Topics("+$Name+")";}
The above ensures that, in a prototype agent, the agent's query is not set within the prototype whereas in all agents inheriting from the prototype the query will be set. The need for a wrapping if() conditional test becomes clearer with this rule:
if(!$IsPrototype){$AgentQuery="Topics("+$Name+")";$Rule="";}
Without the if() test, the latter rule would run and delete itself within the prototype and never set anything in the inheriting agents.
Note too, that if using self-deleting rules via a prototype the act of clearing the rule breaks inheritance for the $Rule attribute.