简体   繁体   中英

What is best way to delete all rows within an arraykey?

I have an entity Contact which has an array entity Specialties. Just a standard one to many relationship. One contact many specialties. (Specialties entity has few columns, might not be relevant). I have a screen to add list of Specialties to a contact on the PCF. I want to add a custom Remove All button on the Contact screen which will delete all values on the array against the specific contact. A contact can have large number of specialties (~10000) What is best way to delete all the elements in the array?

Currently, I have the below function on the action property of the button and it is clocking and timing out.

for(spec in contact.Specialties) 
{contact.removeFromSpecialties(spec) //OOTB remove from array method}

Any other better way to remove ~10000 records from the array entity?

From your question above, I assume that you will have a "Remove All" button in PCF screen with an action that deletes all the speciality records associated with that particular contact, but you will not delete partial records (like one or few records).

Also I assume the entity type of "Speciality" entity is "Editable" or "Retireable".

Keeping the above assumption in mind, you can create a new function and call that function from "Remove All" button action property.

Given below the code that will hard delete the entire records from database table just like you execute a delete query against a DB table,

function removeAllSpecialitiesForContact(contactFromPCF : Contact){
 
  var specialityQuery = Query.make(entity.Speciality).compare(Speciality#Contact, Equals, contactFromPCF.ID)      
  var deleteBuilder = new com.guidewire.pl.system.database.query.DeleteBuilder.DeleteBuilder(specialityQuery)
  deleteBuilder.execute() 
 
}

This new approach might not get timeout after PCF action as you faced already.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM