- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2016 09:05 AM
Could you share a script to delete all records on the contract table and all records on the core_company VENDORs table? There are about 1200 contracts and 4210 vendors. We want to start over and load fresh data for testing
I saw the one on the wiki but was scared to try without asking the community
Thanks
Carl
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2016 09:17 AM
Hi Carl,
Here you go.
For first task :
delCoreCompanyRec();
function delCoreCompanyRec()
{
var gr= new GlideRecord("core_company");
gr.addQuery('vendor', true);
gr.setWorkflow(false); //Don't fire Business rule,notifications
gr.deleteMultiple();
}
For second task :
delContractRecords();
function delContractRecords()
{
var gr= new GlideRecord("ast_contract");
gr.query();
gr.setWorkflow(false); //Don't fire Business rule,notifications
gr.deleteMultiple();
}
Run the above script from Background-scripts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2016 09:12 AM
Hello Carl,
You have two options.
1) if you have access to scripts background as security admin you can truncate the entire table.
(NOTE:this is not available in builds Geneva and newer)
sys.scripts.do
in the mysql section run:
truncate table <tablename>
2) you can build a gliderecord query script to delete all records in your table.
see example 13.1 in this wiki article - GlideRecord - ServiceNow Wiki

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2016 09:17 AM
Hi Carl,
Here you go.
For first task :
delCoreCompanyRec();
function delCoreCompanyRec()
{
var gr= new GlideRecord("core_company");
gr.addQuery('vendor', true);
gr.setWorkflow(false); //Don't fire Business rule,notifications
gr.deleteMultiple();
}
For second task :
delContractRecords();
function delContractRecords()
{
var gr= new GlideRecord("ast_contract");
gr.query();
gr.setWorkflow(false); //Don't fire Business rule,notifications
gr.deleteMultiple();
}
Run the above script from Background-scripts.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2016 09:19 AM
A correction to your code Vendor is an OOB field. Your addQuery should be this addQuery('vendor',true);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2016 09:20 AM
Yes I corrected it asap . I mean the moment I hit enter.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2016 09:25 AM
I was working on some other thread and was late by 2 minutes and saw you have already posted the script. This is not fair pradeep. Let me get few points