Strange behavior with merge variable in popover

Discussion created by JoeSand on Sep 1, 2017
Latest reply on Sep 2, 2017 by JoeSand

This might be down in the weeds, but I wonder if anyone can explain this behavior.


I have, basically, an invoice that has invoice line items displayed in a portal.  One field in each line item is Cost... my cost for this line item... and next to it I placed a popover button that displays a list of different percentage markups, and when you click on your choice it gets copied into the Price field (what the customer pays). They are defined as buttons with a single step "set field."


Rather than create a set of calculation fields to make this list, I decided instead to use global variables which are displayed as Merge Variables.

So, when the user clicks on the popover button, a script is triggered that creates the merge variables used for the list.


Here's the strange part.  When a new line item is created, a cost entered, and the button pressed, the merge variable always displays values from the last line item they were used in... the last line item that had the popover button pressed.  BUT, it only does this the first time!  If I close the popover and open it again is displays correctly, and from that point on it works fine!


The same thing happens on old line items that have never used this function, so it's not specific to newly created records...


I've never used variables this way, did I break some usage rule?