Deleting multiple records in a foundset

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

Deleting multiple records in a foundset

Postby roddy » Thu Jul 14, 2022 2:57 am

When deleting records from a foundset, I have used the following approaches but I am still getting occasional "Update/insert failed, unexpected nr of records affected: expected 1, actual 0" exceptions. I have tried two different methods for achieving this, shown below; is there a preferred way of deleting multiple records from a foundset to avoid the exception being thrown?

Code: Select all
function clearEmptyItems(recInvoice)
{
   var numItems = 0;
   var recItems = [];

   if (utils.hasRecords(recInvoice.invoices_to_invoice_items))
   {
      numItems = recInvoice.invoices_to_invoice_items.getSize();
   }

   //  As we will be deleting the records from the foundset, gather each of them so we don't rely on the (dynamic) index position
   for (var index = 1; index <= numItems; index++)
   {
      var recItem = recInvoice.invoices_to_invoice_items.getRecord(index);
      
      if (isItemEmpty(recItem))
      {
         recItems.push(recItem);
      }
   }
   
   //  Delete the item records from the foundset
   recItems.forEach(function(recItemToDelete)
   {
      recInvoice.invoices_to_invoice_items.deleteRecord(recItemToDelete);
   });
}

and

Code: Select all
   for (var index = 1; index <= recInvoice.invoices_to_invoice_items.getSize(); index++)
   {
      var recItem = recInvoice.invoices_to_invoice_items.getRecord(index);
      
      if (isItemEmpty(recItem))
      {
         recInvoice.invoices_to_invoice_items.deleteRecord(index);
         index--;
      }
   }
roddy
 
Posts: 100
Joined: Mon Oct 26, 2020 12:32 am

Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 9 guests

cron