Transcription

Hi this is Matt at AppWorks, and today we’re going to take a look at best practices for looping scripts. So I have a basic looping script here that runs in two scripts, so one of the best practices that I would say is you should have an outer script that has the looping code in it, and then an inner script that actually does the action for each item.

So let’s step through this and see a couple of other best practices as we go. For one, I think it’s really important to have a lot of logging, so we have a log that tracks the beginning of the script being done, so I’ll step out of that code. Next we really detail – we have a lot of coding documentation in the script that tells me what’s going on with context. 

As I loop through each record, another thing that I think is really important to do is have a test for the found count, so that if you have a found count that’s much larger than you think is reasonable, that you stop because that could really cause a script to blow up. For example, someone changes a field, deletes a field, something changes and this actually ends up with a found set of millions when it’s supposed to have, like, ten. Definitely put a lot of error trapping in for things like that.

Next, when you do your action and step out of your worker script, the inner script, it’s really important in your loop to have some sort of condition to exit the script. So for example, if something changes like the loop is running and some other user deletes a record such that your found count is zero, that you have some sort of an exit, so really think about the states that would make your script normally finish that loop. 

Once everything is done, at the end of the script, I also think it’s a really good idea to have some sort of logging. So those are kind of my best practices right there. Not too many, but for looping scripts you definitely want to have pretty good scripting hygiene. Thanks for your time.