top of page

Experiencing challenges with ServiceNow support?

IKC provides professional, reliable assistance that covers gaps not supported by ServiceNow

and without the high costs of traditional services.

 

Starting from just $1,000

How to Delete All Records from a ServiceNow Table Using a Script

Updated: Mar 29


Cleaning out data from a ServiceNow table is occasionally necessary, especially during testing, development, or when preparing for data migration. However, deleting all records from a table needs careful handling to avoid unintended consequences. This guide explains how to safely and efficiently delete all records from a specific table using ServiceNow scripting.


Common Scenarios and Considerations

Organizations commonly need to remove all existing records from tables like contracts (ast_contract) or vendors (core_company) before loading fresh data for testing purposes. Improper handling of this task can lead to data loss or performance issues if Business Rules or notifications trigger unintentionally during bulk deletions.


Step-by-Step Guide: Deleting Records with GlideRecord

Here are safe, verified scripts you can use in the ServiceNow background script executor to delete all records from specific tables without triggering workflows or notifications.


Delete All Vendor Records in core_company Table

This script deletes all records where the vendor flag is set to true:

function deleteVendorCompanies() {
    var gr = new GlideRecord("core_company");
    gr.addQuery('vendor', true);
    gr.setWorkflow(false); // Prevent Business Rules and notifications
    gr.deleteMultiple();
}

deleteVendorCompanies();

Delete All Records from the Contract Table (ast_contract)

This script deletes every record in the ast_contract table:

function deleteContractRecords() {
    var gr = new GlideRecord("ast_contract");
    gr.setWorkflow(false); // Prevent Business Rules and notifications
    gr.deleteMultiple();
}

deleteContractRecords();

Important Tips:

  • Always set setWorkflow(false) to prevent unwanted Business Rules, workflows, or notifications from triggering.

  • Avoid running gr.query() when using deleteMultiple() because deleteMultiple() already manages querying records internally.

  • Run these scripts cautiously in a non-production environment first to ensure accuracy and avoid data loss.


Alternative Approaches

While scripts provide powerful control, alternative methods exist:

  • Manual deletion: Suitable for small datasets.

  • Scheduled Jobs: Automate periodic deletions.

  • Truncating tables: Historically an option, but less common in newer ServiceNow versions.


Conclusion

Properly scripting bulk deletions in ServiceNow is crucial for efficient data management, particularly in testing or migration phases. By following best practices—such as disabling workflows during bulk operations—you ensure smooth execution without adverse effects on system performance or data integrity. Always validate scripts in a safe, non-production environment before applying them to critical data.

Experiencing challenges with ServiceNow support?

IKC provides professional, reliable assistance that covers gaps not supported by ServiceNow

and without the high costs of traditional services.

 

Starting from just $1,000

CONTACT

New Zealand HQ

Integrated Knowledge Consulting Office

Level 3, 93 Grafton Road

Auckland

South Korea

Integrated Knowledge Consulting Office

BMY역삼타워 6층

서울특별시 강남구 역삼동 678-10번지

 

info@ikconsulting.com

Thanks for submitting!

  • LinkedIn Social Icon

© Copyright 2025 Integrated Knowledge Consulting. All rights reserved.

bottom of page