<?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 How to bulk delete user's via background script after cloning in Community Central forum</title>
    <link>https://www.servicenow.com/community/community-central-forum/how-to-bulk-delete-user-s-via-background-script-after-cloning/m-p/3281968#M3302</link>
    <description>&lt;P&gt;I'm trying to bulk delete 'Inactive' users from the sys_user table using a background script after a clone, but it's taking a long time to delete even 10 users records. After a while, the system becomes unresponsive.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var gr = new GlideRecord('sys_user');
gr.addQuery('active', false);
gr.query();

var count = 0;
while (gr.next() &amp;amp;&amp;amp; count &amp;lt; 10) {
    gr.deleteRecord();
    count++;
}
gs.print('Deleted ' + count + ' inactive users.');&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any better way to doing the above script ?&lt;/P&gt;&lt;P&gt;I tried multiple record deletion as well, but same result.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var gr = new GlideRecord(sys_user);
gr.addQuery('active', false);
gr.setLimit(10); //limit only first  2 record 
gr.query();
gr.deleteMultiple();&lt;/LI-CODE&gt;&lt;P&gt;I noticed there's a 'Clone Cleanup Script', but I've never used it before and I'm not sure how to test it either.&lt;/P&gt;</description>
    <pubDate>Thu, 05 Jun 2025 09:44:14 GMT</pubDate>
    <dc:creator>attanhes</dc:creator>
    <dc:date>2025-06-05T09:44:14Z</dc:date>
    <item>
      <title>How to bulk delete user's via background script after cloning</title>
      <link>https://www.servicenow.com/community/community-central-forum/how-to-bulk-delete-user-s-via-background-script-after-cloning/m-p/3281968#M3302</link>
      <description>&lt;P&gt;I'm trying to bulk delete 'Inactive' users from the sys_user table using a background script after a clone, but it's taking a long time to delete even 10 users records. After a while, the system becomes unresponsive.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var gr = new GlideRecord('sys_user');
gr.addQuery('active', false);
gr.query();

var count = 0;
while (gr.next() &amp;amp;&amp;amp; count &amp;lt; 10) {
    gr.deleteRecord();
    count++;
}
gs.print('Deleted ' + count + ' inactive users.');&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any better way to doing the above script ?&lt;/P&gt;&lt;P&gt;I tried multiple record deletion as well, but same result.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var gr = new GlideRecord(sys_user);
gr.addQuery('active', false);
gr.setLimit(10); //limit only first  2 record 
gr.query();
gr.deleteMultiple();&lt;/LI-CODE&gt;&lt;P&gt;I noticed there's a 'Clone Cleanup Script', but I've never used it before and I'm not sure how to test it either.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jun 2025 09:44:14 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/how-to-bulk-delete-user-s-via-background-script-after-cloning/m-p/3281968#M3302</guid>
      <dc:creator>attanhes</dc:creator>
      <dc:date>2025-06-05T09:44:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to bulk delete user's via background script after cloning</title>
      <link>https://www.servicenow.com/community/community-central-forum/how-to-bulk-delete-user-s-via-background-script-after-cloning/m-p/3281992#M3304</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/179314"&gt;@attanhes&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;May I ask why you want to delete the records? It's generally not a best practice to remove foundation records. However, if you prefer not to see inactive users in sys_user table, you can set up an archive rule to move them to the archived table. I assume this is being done in non-production environments.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;BR /&gt;Siva&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jun 2025 10:10:19 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/how-to-bulk-delete-user-s-via-background-script-after-cloning/m-p/3281992#M3304</guid>
      <dc:creator>J Siva</dc:creator>
      <dc:date>2025-06-05T10:10:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to bulk delete user's via background script after cloning</title>
      <link>https://www.servicenow.com/community/community-central-forum/how-to-bulk-delete-user-s-via-background-script-after-cloning/m-p/3282012#M3305</link>
      <description>&lt;P&gt;What you want to always do is that you name your variables in unique ways. Never call your variable "GR" or "current" etc. as you're potentially allowing other BR's to overwrite your current job.&lt;BR /&gt;For example if you have a script that loops through incidents with GR variable and then you have an update BR that aborts action for GR, then you're potentially losing each update.&lt;BR /&gt;&lt;BR /&gt;Also, you can prevent BR's from running.&lt;BR /&gt;Just add setWorkflow(false) into your script and no BR's are run and deleting is faster. Of course I don't recommend doing it if you have some kind of delete logic in your table that has to be run (deleting related records for example).&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var userDelete = new GlideRecord('sys_user');
userDelete.addQuery('active', false);
userDelete.setLimit(10);
userDelete.query();
userDelete.setWorkflow(false);
userDelete.deleteMultiple();&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Try this and see if it feels faster.&lt;BR /&gt;Also, before deleting anything, you might want to first log (userDelete.getRowCount()) rowCount to make sure that your script is going to delete the correct records. I always first check the list view on a table with my query and then log the amount of rows to make sure I'm not accidentally deleting wrong records.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jun 2025 10:13:44 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/how-to-bulk-delete-user-s-via-background-script-after-cloning/m-p/3282012#M3305</guid>
      <dc:creator>Weird</dc:creator>
      <dc:date>2025-06-05T10:13:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to bulk delete user's via background script after cloning</title>
      <link>https://www.servicenow.com/community/community-central-forum/how-to-bulk-delete-user-s-via-background-script-after-cloning/m-p/3282017#M3306</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/179314"&gt;@attanhes&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;That is correct this process can be slow since there are many related records (like sys_user_role, sys_user_group, approvals, etc.&lt;BR /&gt;Also related to&amp;nbsp;Clone Cleanup Scripts , i believe it only run during an actual clone.&lt;BR /&gt;&lt;BR /&gt;This Article may resolve your query -&amp;nbsp;&lt;A href="https://www.servicenow.com/community/developer-forum/i-would-like-delete-the-multiple-users-in-the-user-table-by-the/m-p/2199398" target="_blank" rel="noopener"&gt;https://www.servicenow.com/community/developer-forum/i-would-like-delete-the-multiple-users-in-the-user-table-by-the/m-p/2199398&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Thank You&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jun 2025 10:14:47 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/how-to-bulk-delete-user-s-via-background-script-after-cloning/m-p/3282017#M3306</guid>
      <dc:creator>abidsiddiqu</dc:creator>
      <dc:date>2025-06-05T10:14:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to bulk delete user's via background script after cloning</title>
      <link>https://www.servicenow.com/community/community-central-forum/how-to-bulk-delete-user-s-via-background-script-after-cloning/m-p/3282112#M3307</link>
      <description>&lt;P&gt;Thanks, everyone. My goal is to clone configuration only to the sandbox environment for a project. I was able to successfully separate the data and clone configuration-only for all modules, except for the sys_user table.&lt;/P&gt;&lt;P&gt;When I excluded the sys_user table and its associated tables as advice by Service Now, certain functionalities broken even though XML import into sandbox.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So now I'm working on Plan B — cloning all users and then deleting the unwanted users in the sandbox environment which is not ideal.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jun 2025 11:30:57 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/how-to-bulk-delete-user-s-via-background-script-after-cloning/m-p/3282112#M3307</guid>
      <dc:creator>attanhes</dc:creator>
      <dc:date>2025-06-05T11:30:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to bulk delete user's via background script after cloning</title>
      <link>https://www.servicenow.com/community/community-central-forum/how-to-bulk-delete-user-s-via-background-script-after-cloning/m-p/3282140#M3308</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/179314"&gt;@attanhes&lt;/a&gt;&amp;nbsp;ok got it..&lt;/P&gt;&lt;P&gt;Try to run the same in fix script (run background).&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jun 2025 12:04:09 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/how-to-bulk-delete-user-s-via-background-script-after-cloning/m-p/3282140#M3308</guid>
      <dc:creator>J Siva</dc:creator>
      <dc:date>2025-06-05T12:04:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to bulk delete user's via background script after cloning</title>
      <link>https://www.servicenow.com/community/community-central-forum/how-to-bulk-delete-user-s-via-background-script-after-cloning/m-p/3283736#M3330</link>
      <description>&lt;P&gt;Thanks, J — your tip was very helpful. I archived the unwanted users in the non-prod environments and then cloned the target while excluding the archived(ar_sys_user)table. Problem solved!&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;No needed to run background script after cloning to delete the accounts as unwanted user accounts already left in source in that way.&amp;nbsp; I would never recommend doing this in a production environment as mentioned in J's post. Fortunately, I was working with two non-prod instances for this exercise.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jun 2025 23:09:43 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/how-to-bulk-delete-user-s-via-background-script-after-cloning/m-p/3283736#M3330</guid>
      <dc:creator>attanhes</dc:creator>
      <dc:date>2025-06-06T23:09:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to bulk delete user's via background script after cloning</title>
      <link>https://www.servicenow.com/community/community-central-forum/how-to-bulk-delete-user-s-via-background-script-after-cloning/m-p/3283740#M3331</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/179314"&gt;@attanhes&lt;/a&gt;&amp;nbsp;Glad it helped..&lt;/P&gt;</description>
      <pubDate>Sat, 07 Jun 2025 00:15:04 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/how-to-bulk-delete-user-s-via-background-script-after-cloning/m-p/3283740#M3331</guid>
      <dc:creator>J Siva</dc:creator>
      <dc:date>2025-06-07T00:15:04Z</dc:date>
    </item>
  </channel>
</rss>

