
- 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 02:29 PM
You are Absolutely spot on.
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-26-2019 01:13 PM
Thank you all for your help. I tested the final code that was recommended and I received the correct count that will be deleted.
Now for the final phase should I use deleteRecord() or deleteMultiple () ?
do I still use gr.next ?
Let me know your opinion
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);
}

- 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-30-2019 03:04 PM
Thank you all for your help, tested the script in my dev environment. Deployment/validation successful.