title: Deleting more than 1000 records in SuiteScript 2.X
body: <p>I am trying to write a SuiteScript 2.1 script to delete 5000+ records. NetSuite limits us to 1000 record changes at a time and I have attempted to get around this with a Do While loop that I have used previously. However, I cannot figure out how to loop over the array of IDs for the deletion itself. I've tried a counter to do this but it keeps failing to iterate at times. This is my latest code, it does not work</p>
  <pre><code>        var idArray = [];
          var recordLocation = 0;
          var counter = 0;
          
          do{
              
              
              var s = compPriceSearch.run();
              var deleteSlice = s.getRange({start: recordLocation, end: recordLocation + 1000});  
              deleteSlice.forEach(function(slice){
                  log.debug(&quot;Grabbing records IDs&quot;);
                  id = slice.getValue({
                      name: 'id', 
                      
                  });   
                  idArray.push(id); 
                  // log.debug('The ID is: ', id); 
                  log.debug('the counter is: ', counter);
                    
                  recordLocation++
                  
                  
              });
          }while (deleteSlice.length &gt;= 1000){
              log.debug(&quot;Number of records to be deleted: &quot;, deleteSlice.length);
              var deleteRecordPromise = record.delete({
                  type: 'customrecord_comp_price',
                  id: idArray[counter]
              });
              counter++
              return idArray;
              
              
          }
  </code></pre>
  <p>If I just use a basic for loop I can delete 1000 records, however it then fails as there are over 1000 records needed to delete. Looking for a solution to this and appreciate any input.</p>