- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2018 08:08 AM
Hello,
I am trying to delete 5500 TASK records that have No Assignment Group, No Assigned to and No Parent.
var rec = new GlideRecord('task');
rec.query();
while (rec.next()) {
if (rec.number.startsWith('TASK') && rec.assigned_to.isNull() && rec.opened_by == '64c0bfbcacc95000ac148fcc9e538060' &&
rec.assignment_group.isNull()) {
gs.print(rec.number + ' deleted');
rec.deleteRecord();
}
It worked with just one condition but was deleting records from all apps that extended the Task table.
I am only looking to delete orphaned TASKs, that have no Parent (RITM)
Not sure if the above syntax is correct.
This did work: But I was not able to understand the results. A manual query showed data was deleted, but I am seeing that it deleted additional data that was not opened by the user that I set the query for.
var rec = new GlideRecord('task');
rec.query();
while (rec.next()) {
if (rec.assigned_to == '' && rec.opened_by == '64c0bfbcacc95000ac148fcc9e538060' && rec.assignment_group == '') {
rec.deleteRecord();
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2018 07:05 PM
What I came here to say, but had to scroll through a thread of replies lol. I think sc_task instead of task is your answer.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2018 11:09 AM
Ok. Lets use your script. I just added few more condition to your condition. This should work.
I am not sure, why you are using opened_by in condition. Do you want to delete task only created by a particular user?
var rec = new GlideRecord('task');
rec.query();
while (rec.next()) {
if (rec.parent=='' && rec.assigned_to == '' && rec.opened_by == '64c0bfbcacc95000ac148fcc9e538060' && rec.assignment_group == '' && rec.number.indexOf('TASK')>-1) {
gs.print(rec.number + ' deleted');
rec.deleteRecord();
}
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2018 06:18 PM
Yes, only created by a certain user with no assignment group and no assigned to
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2018 06:49 PM
why not query on sc_task table instead of task? just curious.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2018 07:05 PM
What I came here to say, but had to scroll through a thread of replies lol. I think sc_task instead of task is your answer.