Question

I'm trying to create a loop to delete all portal rows. But the loop doesn't stop. What am i doing wrong?

Go to Portal Row [Select; First]
Loop
  Delete Portal Row [No Dialog]
  Go To Portal Row [Next; Exit after last]
End Loop
Was it helpful?

Solution

I suspect that you have Allow creation of related records through this relationship on in your Relationships graph. This means that there will always be one record in the portal and that record can't be deleted because it is where a user would enter new data.

You could modify your script to something like this:

Go to Portal Row [Select; First]
Loop
   Delete Portal Row [No dialog]
   Go to Portal Row [Select; First]
   Exit Loop If [IsEmpty(relationship::index)]
End Loop

Where relationship::index is a value stored in every field of your foreign table.

Manipulating portals like this can be tricky. You might consider using a Go to Related Records script step go delete the records, instead. Something like:

Set Error Capture [On]
#
# Attempt to go to the related records, creating a new window "delete records"
Go to Related Record [Show only related records; From table: "<relatedtable>"; Using layout: "<relatedlayout>" (<relatedtable>); New window]
#
# If that failed exit the script. We should still be in the same window and layout.
If [not Get ( LastError )]
   Exit Script []
End If
#
# Otherwise delete all found records
Delete All Records [No dialog]
#
# And close the window we created
Close Window [Name: "delete steps"; Current file]
Set Error Capture [Off]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top