Iterate over Leads

Iterate over Leads

I am trying to write a script which will need to find a particular lead OR contact (by email).  My current approach is to get all leads, then iterate over the collection until the appropriate one is found.

Here is my code:
  1. //get the appropriate category
  2. loc = zoho.crm.getRecords("Leads"); //leads or contacts
  3. if (wasContact) {
    1. loc = zoho.crm.getRecords("Contacts");
  4. }
  5. //find by email
  6. oldItem = null;
  7. for each assoc item in loc {
    1. if (item.email == old.doctorEmail && item.pr_account == true) {
      1. oldItem = item;
      2. break;
    2. }
  8. }
I have tried variations on the for each statement (assoc, index, nothing).

However, I receive an error "Form loc does not exist in application", or with the variations previously mentioned, other messages.

What is the best way to approach this?