(Deluge) Filtering fetched records

(Deluge) Filtering fetched records

I am trying to create a script that checks the status of the zoho sign document where the field waiver_status equals sent, unopened or viewed. 

We have thousands of records so I was trying to filter the fetched records but it is telling me I cannot and giving me a generic error. 

The error is on line two. I am guessing 
  1. // Fetch all records in the form Waiver where Waiver_Status equals sent, unopened, or viewed
  2. recordsToProcess = Waivers.filter("(Waiver_Status == 'sent' or Waiver_Status == 'unopened' or Waiver_Status == 'viewed')");

  3. // Loop through each record
  4. for each record in recordsToProcess
  5. {
  6.     // Run the provided code for each record

  7.     // Fetch document by Sign_ID
  8.     res = zoho.sign.getDocumentById(record.Sign_ID.tolong());

  9.     // Check if document retrieval is successful
  10.     if(res.get('status') == "success")
  11.     {
  12.         // Get request status
  13.         request_status = res.get('requests').get('request_status');

  14.         // Process based on request status
  15.         if(request_status == 'completed')
  16.         {
  17.             info "Document signed by all parties";
  18.             record.Waiver_Status = "SIGNED";
  19.         }
  20.         else if(request_status == 'inprogress')
  21.         {
  22.             info 'Document in progress';

  23.             // Get actions
  24.             actions = res.get('requests').get('actions');

  25.             // Loop through each action
  26.             for each i in actions
  27.             {
  28.                 // Check action status
  29.                 if(i.get('action_status') == "UNOPENED" || i.get('action_status') == "VIEWED")
  30.                 {
  31.                     record.Waiver_Status = i.get('action_status');
  32.                 }
  33.             }
  34.         }
  35.         else if(request_status == 'recalled')
  36.         {
  37.             record.Waiver_Status = "RECALLED";
  38.         }
  39.         else if(request_status == 'expired')
  40.         {
  41.             record.Waiver_Status = "EXPIRED";
  42.         }

  43.         // Update the record in Zoho Creator
  44.         Waivers.update(record);
  45.     }
  46. }