You shouldn't need a script to set the price for each item in the portal. A looked up value or auto-enter calculation can use a relationship to look up (copy over) the price from a products table of prices.
The OnObjectEnter trigger can set a field in the layout's table that serves as a match field to a different occurrence of products and thus be used to display an image for what ever portal row is currently "active" in the portal.
Thank you for that tip! I ended up putting the container field inside of the portal row and made that field a looked up value to the inventory layout with the original picture. I then made a new script that set variable to the item in the portal and the script goes to the inventory layout to copy the content of the container with the original image. The script then pastes the content in the container of the portal row. (I set this script to OnObjectEnter). This process seems to work.
It may work, but it's pretty inefficient. Do you realize that what you described copies the same information twice? And you don't need to copy it at all?
Say you have these typical relationships:
Invoices::__pkInoviceID = LineItems::_fkInvoiceID
Products::__pkProductID = LineItems::_fkProductID
Your names may differ than mine but as long as the match fields function the same, it doesn't really matter for what I am about to describe.
Make a new table occurrence of Products and link it to Invoices like this:
Invoices::_fkSelectedProductID = Products|Selected::__pkProductID
You can then add the container field from Products|Selected to your Invoices layout and this script can then make a specific product image appear in that container field:
Set Field [Invoices::_fkSelectedProductID ; LineItems::_fkProductID ]
You'd run that script whenever you select a new value in _fkProductID, when you click a button in the portal row or when you trip the OnObjectEnter trigger for the portal row by clicking or tabbing into any object in the portal row.
Note that you can add a container field from products to the LineItems portal row and it will display the correct product image. there's no need for a look up field to copy the data over.
For an explanation of the notation that I am using, see the first post of: Common Forum Relationship and Field Notations Explained