How to Close Multiple SCTASK?

JLOx
Tera Contributor

I'm very new in ServiceNow and I would like to know how to close Multiple SCTASK.

I was given the job of closing all aging tickets and was granted an administrative role.

 

Can you please help me with the best practice on how to do this?

I have mandatory fields before you can close a task.

 

Which account should I use to assign all these tickets? (should I assign these to the admin account?)

 

No Script for now please if possible.

 

4 REPLIES 4

Sandeep Rajput
Tera Patron
Tera Patron

@JLOx Best way to close all of these tickets would be via a background or fix script. You can create a GlideRecord query to fetch those SC Tasks which you would like to close and run this script to change their state to closed complete.

 

Here is a sample script.

 

// Query to find the SCTASKs you want to close
var taskGR = new GlideRecord('sc_task');

// Add filters to narrow down the tasks you want to close
// For example, to close tasks in a specific RITM
taskGR.addQuery('request_item', 'RITM1234567');

// Uncomment and modify the line below if you want to filter by another field, like the current state
// taskGR.addQuery('state', '1'); // 1 typically represents the 'New' state

taskGR.query();

while (taskGR.next()) {
    // Set the state to "Closed Complete" (7 is usually the value for this state, but verify in your instance)
    taskGR.state = 3; // or 7 depending on your workflow, adjust as needed

    // Optionally, you can set the close notes or other fields
    taskGR.close_notes = 'Closed via script';
    
    // Update the record
    taskGR.update();
}

gs.print('Tasks closed: ' + taskGR.getRowCount());

 

Please make sure to configure the addQuery correctly before running the script. Also do not run this script directly on your production instance.

Hi Sandeep,

 

Thanks for your prompt reply. As of now, I have very limited knowledge of scripting. Can we do this via filtering ticket and selecting the tickets needs to be close

@JLOx This can be also done via filtering through the list and using Update Select option.

 

Screenshot 2024-08-21 at 9.26.56 PM.png

Dr Atul G- LNG
Tera Patron
Tera Patron

HI @JLOx 

 

SCTask must be closed manually based on the action done on same like closed completed or incomplete or skip. 

 

Open the tabel sc_task.list in navigation

A list view wil open

Select one task and with down arrow key , select all task you want to close. like below.

 

AGLearnNGrow_0-1724254729833.png

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************