Sript to Remove Records created on a specific date

carlh
Kilo Guru

Can anyone provide a script to remove records created on a specific date?

Something went wrong today and we ended up with Duplicates of all records on our vendor table.

I need a script that will delete all records created on 7/28/2016 in Core_Company table.

Please let me know and thanks!

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Carl,



Slight modification to the script shared by Abhniay. Enclosed code in function and added setWorkflow line to turn of notification/BR


Script :


delCoreCompanyRec();


function delCoreCompanyRec()


{


var gr= new GlideRecord("core_company");


gr.addEncodedQuery("sys_created_onON2016-07-28@javascript:gs.dateGenerate('2016-07-28','start')@javascript:gs.dateGenerate('2016-07-28','end')");


gr.setWorkflow(false); //Don't fire Business rule,notifications


gr.deleteMultiple();


}


View solution in original post

21 REPLIES 21

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Can you paste whole script as is. Looks like }   is missing.


This is what I pasted in to background



delCoreCompanyRec();


function delCoreCompanyRec()


{


var gr= new GlideRecord("core_company");


gr.addEncodedQuery("sys_created_onON2016-07-28@javascript:gs.dateGenerate('2016-07-28','start')@javascript:gs.dateGenera...)");


gr.setWorkflow(false); //Don't fire Business rule,notifications


gr.deleteMultiple();


}


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Works at my end. Can you please paste again and try once.


abhi_r       Pradeep got this one.   I wish I could mark 2 as the first script was helpful and comforting to see what it was going to do.



I appreciate your help



pradeepksharma     Thank you.   not sure why but the first time it threw that error.   Second round went perfectly.


pradeepksharma



I tried this script again for Contracts. I changed everywhere core_company wasn mentioned to "Contract" and I changed the dates from 2016-07-28 to 2016-08-02



Here's what I got...


find_real_file.png


Here's the script....can you see what they mean about the "compiler exception"?




delContractRec();
function delContractRec()
{
var gr= new GlideRecord("contract");
gr.addEncodedQuery("sys_created_onON2016-08-02@javascript:gs.dateGenerate('2016-08-02','start')@javascript:gs.dateGenera...


('2016-08-02','end')");
gr.setWorkflow(false); //Don't fire Business rule,notifications
gr.deleteMultiple();
}