I am trying to delete 5500 orphaned TASK records that have No Assignment Group, No Assigned to and No Parent.

Cory Miller
Giga Expert

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();
  }
}

 

1 ACCEPTED SOLUTION

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.

View solution in original post

8 REPLIES 8

SanjivMeher
Kilo Patron
Kilo Patron

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.

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();
   }
}

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.

I was unable to make that type of condition (query) work.