Database Reference
In-Depth Information
prevent problems. These few minutes can save you hours of troubleshooting and repair work
on your data later.
Look at what your script is supposed to do and try to think of reasonable exceptions —situ-
ations where your script might not be able to do its job. Thinking of exceptions is important
for two reasons:
▪ If your script always assumes ideal circumstances, it can wreak havoc if your assump-
tions are wrong when it runs. The last thing you need is a wild script running amok in
your data, changing and deleting the wrong things.
Figure 17-20. This first draft of your script doesn't do anything yet. It's just a series of com-
ments that map out, at the most general level, what the script is going to do. You'll add more
and more details as you go. Since these comments are placeholders for the real steps and com-
ments you'll build, each one starts with the word TODO. Use any marker you want, as long as
you can easily tell these placeholder comments apart from the real comments you'll add later.
▪ If a script gets halfway through its job and then discovers that it can't continue, you may
be left with half-finished work. It's usually best to look for the problems up front, so the
script can simply refuse to run if it won't be able to finish. (For more detail, see the box
on the next page.)
For example, the Invoice creation script may run into two potential problems:
▪ How does the script know which job to create an invoice for? This problem is easy to
solve: Make the script available only through a button on the Job layout. That way,
people can run the script only from the right context. In other words, the script always
runs on the job record the user is looking at. Make a comment at the top of your script
that reminds you how the script is run.
▪ What if the job has no timeslips or expenses that haven't been billed? You wind up with
an invoice that has no line items, and you don't want to send that to your customer, nor
do you want that lying around in your database. You can go ahead and create the invoice
and then delete it if it's empty. But this approach uses up an invoice number, and it
Search WWH ::




Custom Search