Delete records on related lists

caliban
Tera Expert

Hi,

 

I'm looking for a way to delete records in related lists when a record is deleted.

If I have a record in Table A and this table has 2 related lists Table B and Table C.  On deleting the record in Table A I would like it to delete the associated records in tables B & C.

Say if was for a Conference booking (Table A) and the related lists were Conference Room (Table B) & Conference Fees (Table C)

I had looked to setup a Before Business Rule running on Table A from a similar question posted on the forum but that hasn't worked 

var conf = new GlideRecord("TABLE B");
conf.addQuery('referenceField that relates to TABLE A', current.sys_id);
conf.deleteMultiple();

Are there any other ways around this?

Many thanks

 

 

1 ACCEPTED SOLUTION

Anurag Tripathi
Mega Patron
Mega Patron

Try This:

 

var conf = new GlideRecord("TABLE B");   /g was in small case previously
conf.addQuery('referenceField that relates to TABLE A', current.sys_id);
conf.deleteMultiple();

 

 

Also id suggest to use setWorkflow(false) if you dont need BRs to run, would improve query performance.

-Anurag

View solution in original post

9 REPLIES 9

Does it matter what reference field I am using in the original table (Table A), the only reference field there is linked to the User table and I don't want it to delete the user record or should I be setting this cascade up using a reference on one of the related lists?

Thanks

You have to set Reference cascade rule to Delete or Cascade on the reference field in child table.

TABLE A record is referred in TABLE B. Let's call the field "refer_to_table_a", the dictionary of this field should have the set Reference cascade rule to Delete or Cascade.

  1. Navigate table_b.do,
  2. Right-click on the "refer_to_table_a" field label and select Configure Dictionary.
  3. Under Related Links, click Advanced view.
  4. Locate the Reference Specification section.
  5. Set the Reference cascade rule to delete/cascade.

 This would delete records in TABLE B that refers TABLE A record that is being deleted.

find_real_file.png

Thanks,

Rajesh

Dubz
Mega Sage

Use an after update/insert/delete business rule if you're changing other records than the current one. 

saichary
Tera Contributor

Hi 

 

if  record is deleted of table  ,then all records in multiple tables with that reference deleted at a single movement ,rather than gliding every table and do.

 

Thanks in advance

davidwarner007
Tera Contributor

Deleting records on related lists depends on the specific database or platform being used. However, here are some general principles that apply to many database systems:

  1. Cascading Deletion: Some database systems support cascading deletion, which means that when a record on the parent table is deleted, all related records on the child table(s) are automatically deleted as well. This can be a convenient and efficient way to handle record deletions, but it should be used with caution because it can lead to unintentional data loss.

  2. Deletion Triggers: Another approach is to use deletion triggers, which are code or scripts that are executed when a record on the parent table is deleted. The trigger can then delete all related records on the child table(s). This approach gives more control over the deletion process, but it requires more setup and maintenance.

  3. Manual Deletion: In some cases, it may be necessary to manually delete records on related lists. For example, if you want to keep some child records even if the parent record is deleted, you may need to manually delete the related records on the child table(s) one by one.

It's important to note that deleting records on related lists can have significant impacts on data integrity and referential integrity, so it's essential to understand the implications of the deletion before proceeding. It's recommended to test the deletion process thoroughly in a non-production environment before executing it in a production environment....