- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2016 12:39 PM
Hi everyone, I'm quite new in ServiceNow so still learning.
I have a Business Rule that deletes child records from a parent table. I have added the code below but for some reason it wouldn't delete the entries. I'm probably missing something here..Any ideas?
var gr = new GlideRecord('table name');
gr.addQuery('u_parent', current.sys_id);
while (gr.next()) {
gr.deleteRecord();
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2016 01:24 PM
You are missing gr.query() here. Use this script and you are good to go
var gr = new GlideRecord('table name');
gr.addQuery('u_parent', current.sys_id);
gr.query();
while (gr.next()) {
gr.deleteRecord();
}
You can also use this to delete multiple records
var gr = new GlideRecord('table name');
gr.addQuery('u_parent', current.sys_id);
gr.deleteMultiple();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2016 02:02 PM
Ow! missed that! My points!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2016 01:33 PM
Glad you got your question answered.