Query about action code to generate both a hoverexpression and $name suffix extracted from a note attribute

I would be grateful for guidance please regarding the following goal. I have a map that shows notes with a $Prototype setting to show that they are a vendor partner. The prototype Vendor notes’ attributes include 2 regarding revenue:

  1. an attribute called $HistoricalRevenue with a numeric value equal to the cumulative revenue generated by that vendor partner to date; and
  2. an attribute called $ExpectedRevenue with a numeric value of forecast revenue.
    I’d like to have this historical numeric value display when I hover the mouse pointer over the note and to have the note $Name display the $ExpectedRevenue value directly after it in the map view (perhaps separated by a colon). Might someone be able to show the action code needed to achieve this please? Cheers, J

You could use a Hover Expression:

If you add a $HoverExpression to the prototype it will be inherited by the notes that have that $Prototype. Or, you can use an agent action to set

$HoverExpression="'Historical: ' + $HistoricalRevenue.format('') + '\n' + 'Expected: ' + $ExpectedRevenue.format('')";

Edit: The agent code contained a mis-escaped new line code, and curly quotes. Fixed.

1 Like

Thanks Paul. This is extremely helpful. Cheers, J

1 Like

I strongly prefer to either inherit an expression from the note’s prototype, or to copy the expression from some other note:

  $HoverExpression=$HoverExpression(/configuration/example)

This avoids headaches with quotation marks, makes testing much easier, and also makes your intentions more clear.

The Inspector—in this case the Text Inspector’s Hover tab offers a reasonable size box for entering the expressions. But, if the expression code needed is long, a further approach to the above is to give your ‘example’ note the (built-in) prototype “Code” and put the expression’s code into the note’s $Text. The prototype ensures normal $Text behaviours like making straight quotes aren’t automatically translated into curly ones—nicer to read but which don’t have the same meaning in action code. Taking such an approach the example above would then become:

$HoverExpression=$Text(/configuration/example)

The ‘example’ can be any note. The choice of source here is just by way of explanation.