Hard to say without physically examining your file. Copy and Paste will both silently fail to work if the referenced field is not on the current layout, so that is one possibility. (And your focus might still be on the other window or layout when you tried to paste.)
Copy and Paste aren't the best options for moving data between your two windows anyway. In addition to the above limitation, if the user copies data to the clipboard and then they run your script, their copied data will be replaced by the itemcode and users can find that both confusing and irritating.
Instead, use set variable with set field to move data from one layout or window to another:
Working from your description of two windows rather than just two layouts here and assuming that both windows are from the same file, this is what you might use:
Set Variable [$ItemCode ; STB::ItemCode]
Select Window [//specify other window here]
Set Field [PBA::ITemCode ; $ItemCode]
I get everything to accept the last variable I don't understand how you get the second part of the equation? The new window is selected but the set field hasn't worked? In my script Set Field I can select the "PBA::ItemCode but I don't know how to program the second part ;$Itemcode]
Thanks for clarification
What version of FileMaker are you using?
$Itemcode is a variable. I'm using it as a "bucket" to carry the ItemCode value from the current record in one window to the current record in the other window. I create this "bucket" in the first line of the script and store the ItemCode in it from the current record of your current window. The final line of code then takes the value from the variable and puts it in the PBA::ItemCode field of your new record.
In older versions of FileMaker that do not support variables, you may have to use a global field for this purpose.
I use 11 advanced. Here is my actual script seems straightforward not sure why is not working.
I have tried different fields as the result and all come up blank?
Your last line should be:
Set Field[PriceBook::Code_PB_sp; $ItemCode ]
Once your focus changes to the other window (also true for changing to a layout based on a different table occurrence), you no longer have automatic access to the current record of the previous window or layout. That's why you have to store the value in a variable before changing layouts.