You likely do not want it on the 'on click event' of a field, because, let's say you scroll back to 3 entries before and you click in the lot number field, that prompt will show up and if your people hit the wrong button your historical data could get destroyed.



What I would likely do is give them a button in the detail section that's labeled 'Copy Previous Record' with the code you have working attached to that button then disable that button if there's a value in your lot number field (I think this possible, but I haven't done any testing to confirm).