
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2019 01:50 PM
Good afternoon,
Need help with this script, trying to delete records from a user table that fit a condition. But record count displays zero.
Condition that I set is records that were created on 04/18/2019.
I have the following, I have not added the delete statement making sure I get the right count first.
Any ideas are welcome.
removechecksjan();
function removechecksjan() {
var gr = new GlideRecord("u_check_drawer");
gr.addEncodedQuery('sys_created_on=2019-04-18');
gr.query();
var deleteCount = 0;
while(gr.next()){
gr.setWorkflow(false);
deleteCount++;
}
gs.print('Records Deleted: '+ deleteCount);
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2019 11:17 AM
Hi Nico,
Although I usually like to use 'deleteMultiple()' for efficiency's sake, in your case I would not. If you read through the reference on GlideRecord, there are a couple of counterindications:
- Your table is named 'u_check_drawer', so I'm guessing there may be some currency values involved. From the reference they state:
"Do not use deleteMultiple() on tables with currency fields. Always delete each record individually" - Also, I noted you are employing 'setWorkflow(false)', from the ref this will not apply to cascade deletes:
"Note: The setWorkflow() method is ignored when subsequently using either the deleteProblem() or deleteMultiple() methods to cascade delete."
Thanks,
-Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2019 01:55 PM
removechecksjan();
function removechecksjan() {
var gr = new GlideRecord("u_check_drawer");
gr.addEncodedQuery("sys_created_onON2019-04-18@javascript:gs.dateGenerate('2019-04-18','start')@javascript:gs.dateGenerate('2019-04-18','end')");
gr.query();
while(gr.next()){
gr.setWorkflow(false);
gr.deleteRecord();
gs.print('Records Deleted: '+ deleteCount);
}
}
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2019 02:07 PM
First check the record count
removechecksjan();
function removechecksjan()
{
var deleteCount = 0;
var gr = new GlideRecord("u_check_drawer");
gr.addEncodedQuery('sys_created_on=2019-04-18');
gr.query();
var rec_count = gr.getRowCount();
gs.print('Records to be deleted : '+ rec_count );
while(gr.next())
{
gr.setWorkflow(false);
deleteCount++;
}
gs.print('Records Deleted: '+ deleteCount);
}
Vinod Kumar Kachineni
Community Rising Star 2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2019 02:23 PM
Hi nico,
Try using the table filter in List view to generate your query statement. The field sys_created_on is a GlideDateTime field, so I do not think it would be equal to a simple date. Using the table filter gives this result for your query statement:
sys_created_onON2019-04-18@javascript:gs.dateGenerate('2019-04-18','start')@javascript:gs.dateGenerate('2019-04-18','end')
Once you build the filter on a list, just right-click on the filter breadcrumbs to copy the underlying query statement. Give that a try.
Thanks,
-Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2019 02:24 PM
I think problem is with your date check in the EncodedQuery
Try this out....
removechecksjan();
function removechecksjan() {
var gr = new GlideRecord("u_check_drawer");
//gr.addEncodedQuery('sys_created_on=2019-04-18');
gr.addEncodedQuery("sys_created_onON2019-04-18@javascript:gs.dateGenerate('2019-04-18','start')@javascript:gs.dateGenerate('2019-04-18','end')");
gr.query();
var deleteCount = 0;
while(gr.next()){
gr.setWorkflow(false);
deleteCount++;
}
gs.print('Records Deleted: '+ deleteCount);
}