Jump to content

delete and go to next record script


This topic is 7907 days old. Please don't post here. Open a new topic instead.

Recommended Posts

hi

i have a problem doing a loop that deletes records;

(btw - is there a way to copy stuff from the script dialog box!?)

so the loop works fine but when deletes the record instead of going to the next record - it jumps one - i understand that the logic is that if deleted "this" one the "next" record is already there and you don't have to use the "go to the next record" command but what if i don't need the "next" record deleted but the fifth after that.

like i need a loop that goes through a db and deletes only certain records - they might be consecutive records or not...

i hope this explanation gives an idea of my problem...

Link to comment
Share on other sites

You've obviously figured out that whenever you delete or omit a record inside a loop, the new current record is the one immediately following the one you deleted. So, when you execute a Go to Record/request[next] step, it has the effect of skipping that record.

The simplest solution to this problem is to start at the last record and step backwards through the set of records using the Go to Record/request [previous] step.


Go to Record/request [last]

Loop

If [<<condition for deleting record>>]

Delete record

End If

Go to record/request[previous][exit after first]

End loop


The other technique is to use an If/else construct like this:


Go to Record/request [first]

Loop

If [<<condition for deleting record>>]

Delete record

Else

Go to record/request[next][exit after last]

End If

End loop


A word of warning though, if you delete the last record in the set, make sure that the script is properly set up to terminate without getting into an endless loop. I've encountered certain situations where skipping the last record causes the 'exit after last' to fail.

Link to comment
Share on other sites

Another way of dealing with this would be to use the "Omit Record" step instead of delete. Your script would go like this:-

Go to Record/request [first]

Loop

If [<<condition for deleting record>>] Omit record

Else

Go to record/request[next][exit after last]

End If

End loop

Show Omitted

Delete All Records

This way you should avoid getting into an endless loop.

Link to comment
Share on other sites

This topic is 7907 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.