- 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 08:14 AM
Try the below script
var rec = new GlideRecord('task');
rec.addEncodedQuery('parentISEMPTY^assignment_groupISEMPTY^assigned_toISEMPTY^opened_by=62826bf03710200044e0bfc8bcbe5df1^numberSTARTSWITHTASK');
rec.query();
while (rec.next()) {
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
03-06-2018 10:40 AM
I tried and got a message "Script completed in 8 seconds", but no results, no records deleted.
I was only able to get results with this script:
var rec = new GlideRecord('task');
rec.query();
while (rec.next()) {
if (rec.assigned_to == '' && rec.opened_by == '64c0bfbcacc95000ac148fcc9e538060' && rec.assignment_group == '') {
rec.deleteRecord();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2018 10:49 AM
Sorry. One correction
var rec = new GlideRecord('task');
rec.addEncodedQuery('parentISEMPTY^assignment_groupISEMPTY^assigned_toISEMPTY^opened_by=64c0bfbcacc95000ac148fcc9e538060^numberSTARTSWITHTASK');
rec.query();
while (rec.next()) {
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
03-06-2018 11:00 AM
I was unable to make that type of condition (query) work.