How to create a rule for the OutlineBackgroundColor Attribute?

Hi! I’m trying to figure out how to implement this rule in the inspector: if a note becomes a container and contains more than one note, then its background should be a certain color. Currently, I’m doing this by manually setting the OutlineBackgroundColor attribute to #cad1ce as follows:

Thanks for your answers.

No problem, this can be done in a rule—re edict depending on urgency—and might best be applied via prototype. Here is the code:

if($ChildCount){
   $OutlineBackgroundColor="#cad1ce";
}else{
   $OutlineBackgroundColor=;
}

To unpack a this little:

  • the if() conditional query is a shorthand way of saying “is there a child?”. $ChildCount defaults to zero, so any non-default value indicates there are one or more children.
  • the else condition ensures the $OutlineBackgroundColor is reset to the document’s default if there are children that are then removed. In other words, this ensures that emptying a container resets the default colour.

†. Ideally, turn the rule/edict ‘off’ in the prototype. If using the Inspector, it is the tick-box lower left: un-ticked means it won’t run in the prototype. For this very reason, the disablement attributes for rules and edicts are not inherited. :slight_smile:

1 Like

I’d add, for later readers, that the if() conditional code doesn’t have to set (only)$OutlineBackgroundColor. The example does that because this was the starting question. But it could set a badge, a colour ($Color so it shows in map view), etc.

The key element here is testing a condition (and action code query): “do I have a child?” Based on that we set one or more attribute(s). As importantly, we test if the condition is met no longer in which case we undo the settings made to indicate the presence of children.

Indeed, here we test for children. But the same concept applies for all sorts of conditions (amount of text in/out-bound link count, etc.).

HTH :slight_smile:

†. If $ChildCount may not look like a query as it is just a shorthand way of writing $ChildCount>0 or $ChildCount!=0. However, you may find it useful when first using these techniques to write out the longer form until you have a natural sense of the implicit meaning of shorter form. Both work, and the explicit form won’t slow your document. Use whichever form you find useful.

1 Like

As always, it works perfectly! Thank you for your help.

2 Likes