- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2018 04:31 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2018 04:40 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2018 04:40 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2018 06:37 AM
Hi,
Thanks for the response. I've updated the typo in original question (lower case g) thanks for pointing it out.
When I delete the record in table A it only deletes the accompanying record in table B, not table C. Is it as simple as creating another Business Rule for table C? Or can I get the required result into a single Business Rule?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2018 06:44 AM
In the same BR you can first delete items for table b and then for table c
Same Script just change table and field name

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2018 05:53 AM
Have you considered the cascade delete option. You can refer our documentation Configure cascade delete rules for more details.
- Navigate to a reference field on a form.
- Right-click the field label and select Configure Dictionary.
- Under Related Links, click Advanced view.
- Locate the Reference Specification section.
- In the Reference cascade rule field, select one of the following options.
Option Description Clear or -- None -- Deleting a record clears references (default option). Delete or Cascade Deleting a record also deletes all referencing records. For example, when a user record is deleted, any incidents assigned to the user are also deleted. Caution: Use this method with caution.
Thanks,
Rajesh