How can I delete records in a loop?
<p>I'm writing a business service which needs to iterate all the records in a BC, and delete some of them:</p>



<pre class="lang-js prettyprint-override"><code>bc.ExecuteQuery(ForwardBackward);
var isRecord = bc.FirstRecord();
while (isRecord) {
  if (...) {
    bc.DeleteRecord();
  }
  isRecord = bc.NextRecord();
}
</code></pre>

<p>However, <a href="https://docs.oracle.com/cd/E14004_01/books/OIRef/Interfaces_Reference11.html#wp1010759" rel="nofollow">DeleteRecord moves the cursor to the next one</a>, so I would be skipping a record for each one being deleted, which is not what I want. Is there any standard-<em>ish</em> way to solve this?</p>

<p>I guess I could just make two loops, one for the checks and another for the deletion... it would work, but it just feels silly to iterate twice over the records, there has to be a better way than this:</p>

<pre class="lang-js prettyprint-override"><code>bc.ExecuteQuery(ForwardBackward);
var isRecord = bc.FirstRecord();
var list = [];
while (isRecord) {
  if (...) {
    list.push(bc.GetFieldValue("Id"));
  }
  isRecord = bc.NextRecord();
}

bc.ClearToQuery();
bc.SetSearchSpec("Id", "='" + list.join("' OR ='") + "'");  // "='1-ABCD' OR ='1-1234'"
bc.ExecuteQuery(ForwardBackward);
while (bc.FirstRecord()) {
  bc.DeleteRecord();
}
</code></pre>