Exactly how are you doing this? I suspect that you are using the web viewer to display a PDF of the invoice?
If so, you should store the URL in a field defined in your invoice table and then set your web viewer to get the URL from this text field. Your script can than store the URL expression in this text field. That way, changing records will also result in your web viewer getting it's URL from a new record and it will then update to display the new PDF.