How to resolve the background scripts issue

mania
Tera Contributor

Hi,

I have 5 lakhs+ records in sc_req_item table so we have used background script to delete the records and close the background scripts tab but still it is running i want to stop the backgroung script because based on the below script it is deleting 50 records instead of 10000 records.

Can anyone please help on this, It will be useful.

var batchSize = 10000; // Process 10,000 records at a time

var totalDeleted = 0;

var gr;

do {

    gr = new GlideRecord('sc_req_item');

    gr.setLimit(batchSize);

    gr.query();

    var count = 0;

    while (gr.next()) {

        gr.deleteRecord();

        count++;

    }

    totalDeleted += count;

    gs.sleep(1000); // Prevent system overload

} while (count > 0);

gs.print("Deleted " + totalDeleted + " records from sc_req_item.");

 

5 REPLIES 5

maheshkhatal
Mega Sage

@mania on the background script page you can write cancelt_my_transaction. 

Add https://dev99999.service-now.com/cancel_my_transaction.

 

Mark my response as helpful if it helped resolve your doubt.

Thanks,

Mahesh.

Ankur Bawiskar
Tera Patron
Tera Patron

@mania 

you can cancel the transaction

Go to Active Transactions then kill your background script, it will stop.

Best is to use fix script and let that run in background

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@mania 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

HasanM
Tera Contributor

Instead of using background script . you can "Delete jobs" and if you want that deleted records back you can also reverte back in "Delete jobs".