Delete all rows from business object using groovy in vbcs

Users can navigate to Business Objects ( BO ) -> Objects -> Select Object ( ex: Department or Employee ) -> Business Rules -> Object Function -> New Object Function

In Object function we can write groovy code to do operations

Groovy code to delete all rows in business object

The following code will fetch all the data from a particular BO and delete it.

def vo = newView('EmployeeBO')
vo.executeQuery()
while (vo.hasNext()) {
  def curRow = vo.next()
  curRow.remove()
}

We can write this code in a separate Business object object function and call it using rest API.

This will be useful in scenarios where we want to delete large amount of data. Instead of calling delete API for each BO we can call the above object function to delete multiple records in one API call.

We can also customize this code by adding query to vo like below

def vo = newView('EmployeeBO')
vo.appendViewCriteria("Salary between 50000 and 75000")
vo.executeQuery()
while (vo.hasNext()) {
  def curRow = vo.next()
  curRow.remove()
}

or by checking some logic using groovy like below

def vo = newView('EmployeeBO')
vo.executeQuery()
while (vo.hasNext()) {
  def curRow = vo.next()
  if ( curRow.Salary >= 5000 && curRow.Salary <= 75000 ) {
    curRow.remove()
  }
}

You can find more code on groovy capabilities from the following reference.

https://docs.oracle.com/en/cloud/paas/app-builder-cloud/visual-builder-groovy/groovy-tips-and-techniques.html#groovy-tips-and-techniques