<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Need help with this script, trying to delete records from a user table that fit a condition in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/need-help-with-this-script-trying-to-delete-records-from-a-user/m-p/1474565#M131491</link>
    <description>&lt;P&gt;Good afternoon,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Need help with this script, trying to delete records from a user table that fit a condition. But record count displays zero.&lt;/P&gt;
&lt;P&gt;Condition that I set is records that were created&amp;nbsp; on 04/18/2019.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following, I have not added the delete statement making sure I get the right count first.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any ideas are welcome.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;removechecksjan();&lt;/P&gt;
&lt;P&gt;function removechecksjan() {&lt;BR /&gt; var gr = new GlideRecord("u_check_drawer");&lt;BR /&gt; gr.addEncodedQuery('sys_created_on=2019-04-18');&lt;BR /&gt; gr.query();&lt;BR /&gt; var deleteCount = 0;&lt;BR /&gt; while(gr.next()){&lt;BR /&gt; gr.setWorkflow(false);&lt;BR /&gt; deleteCount++;&lt;BR /&gt; }&lt;BR /&gt; gs.print('Records Deleted: '+ deleteCount);&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 24 Apr 2019 20:50:41 GMT</pubDate>
    <dc:creator>nico2</dc:creator>
    <dc:date>2019-04-24T20:50:41Z</dc:date>
    <item>
      <title>Need help with this script, trying to delete records from a user table that fit a condition</title>
      <link>https://www.servicenow.com/community/developer-forum/need-help-with-this-script-trying-to-delete-records-from-a-user/m-p/1474565#M131491</link>
      <description>&lt;P&gt;Good afternoon,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Need help with this script, trying to delete records from a user table that fit a condition. But record count displays zero.&lt;/P&gt;
&lt;P&gt;Condition that I set is records that were created&amp;nbsp; on 04/18/2019.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following, I have not added the delete statement making sure I get the right count first.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any ideas are welcome.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;removechecksjan();&lt;/P&gt;
&lt;P&gt;function removechecksjan() {&lt;BR /&gt; var gr = new GlideRecord("u_check_drawer");&lt;BR /&gt; gr.addEncodedQuery('sys_created_on=2019-04-18');&lt;BR /&gt; gr.query();&lt;BR /&gt; var deleteCount = 0;&lt;BR /&gt; while(gr.next()){&lt;BR /&gt; gr.setWorkflow(false);&lt;BR /&gt; deleteCount++;&lt;BR /&gt; }&lt;BR /&gt; gs.print('Records Deleted: '+ deleteCount);&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 20:50:41 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/need-help-with-this-script-trying-to-delete-records-from-a-user/m-p/1474565#M131491</guid>
      <dc:creator>nico2</dc:creator>
      <dc:date>2019-04-24T20:50:41Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with this script, trying to delete records from a user table that fit a condition</title>
      <link>https://www.servicenow.com/community/developer-forum/need-help-with-this-script-trying-to-delete-records-from-a-user/m-p/1474566#M131492</link>
      <description>&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;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);
}

 }&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Apr 2019 20:55:31 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/need-help-with-this-script-trying-to-delete-records-from-a-user/m-p/1474566#M131492</guid>
      <dc:creator>Prateek kumar</dc:creator>
      <dc:date>2019-04-24T20:55:31Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with this script, trying to delete records from a user table that fit a condition</title>
      <link>https://www.servicenow.com/community/developer-forum/need-help-with-this-script-trying-to-delete-records-from-a-user/m-p/1474567#M131493</link>
      <description>&lt;P class="ng-scope"&gt;First check the record count&amp;nbsp;&lt;/P&gt;
&lt;P class="ng-scope"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="ng-scope"&gt;removechecksjan();&lt;/P&gt;
&lt;P class="ng-scope"&gt;function removechecksjan()&lt;/P&gt;
&lt;P class="ng-scope"&gt;{&lt;/P&gt;
&lt;P class="ng-scope"&gt;var deleteCount = 0;&lt;BR /&gt;var gr = new GlideRecord("u_check_drawer");&lt;BR /&gt;gr.addEncodedQuery('sys_created_on=2019-04-18');&lt;BR /&gt;gr.query();&lt;/P&gt;
&lt;P class="ng-scope"&gt;var rec_count = gr.getRowCount();&lt;/P&gt;
&lt;P class="ng-scope"&gt;gs.print('Records to be deleted :&amp;nbsp; '+ rec_count&amp;nbsp;);&lt;/P&gt;
&lt;P class="ng-scope"&gt;while(gr.next())&lt;/P&gt;
&lt;P class="ng-scope"&gt;{&lt;BR /&gt;gr.setWorkflow(false);&lt;BR /&gt;deleteCount++;&lt;/P&gt;
&lt;P class="ng-scope"&gt;&lt;BR /&gt;}&lt;BR /&gt;gs.print('Records Deleted: '+ deleteCount);&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 21:07:35 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/need-help-with-this-script-trying-to-delete-records-from-a-user/m-p/1474567#M131493</guid>
      <dc:creator>vkachineni</dc:creator>
      <dc:date>2019-04-24T21:07:35Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with this script, trying to delete records from a user table that fit a condition</title>
      <link>https://www.servicenow.com/community/developer-forum/need-help-with-this-script-trying-to-delete-records-from-a-user/m-p/1474568#M131494</link>
      <description>&lt;P&gt;Hi nico,&lt;/P&gt;
&lt;P&gt;Try using the table filter in List view to generate your query statement.&amp;nbsp; The field sys_created_on is a GlideDateTime field, so I do not think it would be equal to a simple date.&amp;nbsp; Using the table filter gives this result for your query statement:&lt;/P&gt;
&lt;P style="padding-left: 30px;"&gt;&lt;STRONG&gt;sys_created_onON2019-04-18@javascript:gs.dateGenerate('2019-04-18','start')@javascript:gs.dateGenerate('2019-04-18','end')&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you build the filter on a list, just right-click on the filter breadcrumbs to copy the underlying query statement.&amp;nbsp; Give that a try.&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;-Brian&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 21:23:08 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/need-help-with-this-script-trying-to-delete-records-from-a-user/m-p/1474568#M131494</guid>
      <dc:creator>BrianD502676804</dc:creator>
      <dc:date>2019-04-24T21:23:08Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with this script, trying to delete records from a user table that fit a condition</title>
      <link>https://www.servicenow.com/community/developer-forum/need-help-with-this-script-trying-to-delete-records-from-a-user/m-p/1474569#M131495</link>
      <description>&lt;P&gt;I think problem is with your date check in the EncodedQuery&lt;/P&gt;
&lt;P&gt;Try this out....&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;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);
}

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Apr 2019 21:24:19 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/need-help-with-this-script-trying-to-delete-records-from-a-user/m-p/1474569#M131495</guid>
      <dc:creator>A-N</dc:creator>
      <dc:date>2019-04-24T21:24:19Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with this script, trying to delete records from a user table that fit a condition</title>
      <link>https://www.servicenow.com/community/developer-forum/need-help-with-this-script-trying-to-delete-records-from-a-user/m-p/1474570#M131496</link>
      <description>&lt;P&gt;You are Absolutely spot on.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 21:29:42 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/need-help-with-this-script-trying-to-delete-records-from-a-user/m-p/1474570#M131496</guid>
      <dc:creator>Prateek kumar</dc:creator>
      <dc:date>2019-04-24T21:29:42Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with this script, trying to delete records from a user table that fit a condition</title>
      <link>https://www.servicenow.com/community/developer-forum/need-help-with-this-script-trying-to-delete-records-from-a-user/m-p/1474571#M131497</link>
      <description>&lt;P&gt;Thank you all for your help. I tested the final code that was recommended and I received the correct count that will be deleted.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now for the final phase should I use deleteRecord() or deleteMultiple () ?&lt;/P&gt;
&lt;P&gt;do I still use gr.next ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let me know your opinion&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;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);
}&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Apr 2019 20:13:18 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/need-help-with-this-script-trying-to-delete-records-from-a-user/m-p/1474571#M131497</guid>
      <dc:creator>nico2</dc:creator>
      <dc:date>2019-04-26T20:13:18Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with this script, trying to delete records from a user table that fit a condition</title>
      <link>https://www.servicenow.com/community/developer-forum/need-help-with-this-script-trying-to-delete-records-from-a-user/m-p/1474572#M131498</link>
      <description>&lt;P&gt;Hi Nico,&lt;/P&gt;
&lt;P&gt;Although I usually like to use 'deleteMultiple()' for efficiency's sake, in your case I would not.&amp;nbsp; If you read through the reference on GlideRecord, there are a couple of counterindications:&lt;/P&gt;
&lt;UL&gt;&lt;LI&gt;Your table is named 'u_check_drawer', so I'm guessing there may be some currency values involved.&amp;nbsp; From the reference they state:&lt;BR /&gt;"Do not use &lt;SPAN class="keyword apiname"&gt;deleteMultiple()&lt;/SPAN&gt; on tables with currency fields. Always delete each record individually"&lt;/LI&gt;&lt;LI&gt;Also, I noted you are employing 'setWorkflow(false)', from the ref this will not apply to cascade deletes:&lt;BR /&gt;"&lt;SPAN class="note__title notetitle"&gt;Note:&lt;/SPAN&gt; The &lt;SPAN class="keyword apiname"&gt;setWorkflow()&lt;/SPAN&gt; method is ignored when subsequently using either the &lt;SPAN class="keyword apiname"&gt;deleteProblem()&lt;/SPAN&gt; or &lt;SPAN class="keyword apiname"&gt;deleteMultiple()&lt;/SPAN&gt; methods to cascade delete."&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;-Brian&lt;/P&gt;</description>
      <pubDate>Mon, 29 Apr 2019 18:17:06 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/need-help-with-this-script-trying-to-delete-records-from-a-user/m-p/1474572#M131498</guid>
      <dc:creator>BrianD502676804</dc:creator>
      <dc:date>2019-04-29T18:17:06Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with this script, trying to delete records from a user table that fit a condition</title>
      <link>https://www.servicenow.com/community/developer-forum/need-help-with-this-script-trying-to-delete-records-from-a-user/m-p/1474573#M131499</link>
      <description>&lt;P&gt;Thank you all for your help, tested the script in my dev environment.&amp;nbsp; Deployment/validation successful.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2019 22:04:16 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/need-help-with-this-script-trying-to-delete-records-from-a-user/m-p/1474573#M131499</guid>
      <dc:creator>nico2</dc:creator>
      <dc:date>2019-04-30T22:04:16Z</dc:date>
    </item>
  </channel>
</rss>

