0

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?

Arjun
  • 108
  • 9
  • Do you really need to remove 10,000 records via a PCF? Will this happen often enough as to need to have this in a PFC? Would a Batch Process do the work? – J.A.I.L. Jan 25 '22 at 11:22
  • Unfortunately, Yes. It does happen fairly frequently through the pcf. – Arjun Jan 26 '22 at 12:03

1 Answers1

1

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.

Arun Kumar Mani
  • 337
  • 2
  • 7
  • I have the below based on your suggestion. `var specialityQuery = Queries.createQuery(Speciality)` `specialityQuery.compare(Speciality#Contact, Equals, contactFromPCF.ID)` `var del=new com.guidewire.pl.system.database.query.DeleteBuilder(specialityQuery)` `del.execute()` I am trying to find any documentation for an impact analysis. Is there any material available that you are aware of? – Arjun Jan 31 '22 at 09:37
  • Arjun, What you can do is, try to install a java decompiler in your machine and search for DeleteBuilder.class file in your studio (in the same package used in your import section). You can refer the "execute" method in which the actual code for constructing the delete query that hard deletes the records from your DB table. Delete query is constructed in similar way like you execute delete query in SQL management studio. You Should'nt have any impact as GW OOTB BeforeUpgradeDeleteBuilder.gs also uses the same execute method to delete data during server start up. – Arun Kumar Mani Jan 31 '22 at 16:56
  • Thank you. Tried this and the results are remarkable. – Arjun Feb 01 '22 at 11:40
  • Great news. Glad that worked for you !! – Arun Kumar Mani Feb 01 '22 at 12:00