Script works inconsistently
Im using FM Pro 9 (I have access to 9 Adv also).
OK, here's the general idea with my database. There is a CPU table with computers and information about those computers (called CPU_Db). There is also an IP table with local and public IPs for those computers (called IP_Db). Both tables have an "Item Name" field which is the field that ties the two tables together via thier relationship.
I have a script that someone in a forum helped me create, it changes the related Item Name in the IP_Db table from within a form view of the CPU_Db table, and I do not allow editing of the Item Name manually without the script in either table. The reason I need the script is because changing the Item Name in either table without changing it to the same thing in the other will cause the related record in the other table to not be related anymore. The problem is that the script works inconsistently. Sometimes it doesnt change the related Item Name field in the IP_Db table. Ive managed to figure out a few thing about when it works and when it doesnt, so there are some hints as to whats going on....I just dont know enough to nail it down and fix it. The best clue I have is if you run the script the first time without changing the name to a different name (just leave the default which is the current name) and then immediately run it it again but this time change the name, it will work everytime. This says to me that there is something that happens during the first run of the script that puts the database into a state that is conducive to running this script properly. I thought maybe it had something to do with open records so I added the Commit Records line at the top which wasnt there originally. I also added the same commit records line to the top of the scripts that run when you click buttons to switch layouts, but it doesnt help.
Here is the script, any help would be greatly appreciated!!
Commit Records/Requests 
Set Variable [$OrigWindowName; Value:Get(WindowName)]
If [Count ( IP_Db::Item Name ) = 0]
.. Show Custom Dialog ["Enter New Item Here"; CPU_Db::Item Name]
.. Exit Script 
Go to Related Records [Show ONLY related records; From table: "IP_Db"; Using layout: "IP_Table" (IP_Db); New window] // new window gets named "Related IPs" here
Select Window [Name: $OrigWindowName]
Show Custom Dialog ["Enter New Item Here"; CPU_Db::Item Name]
If [Get(LastMessageChoice) = 2]
.. Close Window [Name: "Related IPs"; Current file]
.. Exit Script 
Set Variable [$NewItemName; Value: CPU_Db::Item Name]
Select Window [Name: "Related IPs"; Current file]
Go to Record/Request/Page [First]
.. Set Field [IP_Db::Item Name; $NewItemName]
.. Go to Record/Request/Page [Next, Exit After Last]
Close Window [Name: "Related IPs"; Current file]
Select Window [Name: $OrigWindowName; Current file]