Sounds like your script is looping thru the wrong portal. The immediate fix is to give your portal an object name and specify it in your place of using Go to object to place the focus on the tab panel.
But it you do not have to loop thru a portal at all to get this info. ExecuteSQL could produce this list. The list function can also be used if you define a calculation field that combines all the fields that make up one row for use with the portal row.
Thanks Phil. The wrong portal was "active". So like you said; I just gave it ab object name and the loop functioned correctly.