System becomes unresponsive while updating 33k records
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2024 06:08 AM
Hi,
I have a UI action called "Pause Site ID". Activating this UI action triggers a script include containing the necessary code. This code retrieves the specified Site ID and locates all associated accounts. It then updates certain fields for each account sequentially. In instances where a Site ID is linked to approximately 33,000 records, the update process takes about 8 minutes, causing the system to become unresponsive during this time.
Sample code:
var site_id = this.getParameter('sysparm_site_id');
var accounttype = this.getParameter('sysparm_account_type');
var ga = new GlideRecord('customer_account');
ga.addQuery("u_site_id", site_id);
ga.addQuery("u_account_type", account_type);
ga.query();
if (ga.getRowCount() != 0) {
gs.addInfoMessage("Account pause in progress.");
while (ga.next()) {
ga.u_pause_lifecycle = true;
ga.u_pause_un_pause = true;
ga.update();
}
} else if (ga.getRowCount() == 0) {
return "Empty";
}
I have used updateMultiple() also. But still it is taking that much of time. Could you please let me know is there a way to update it faster?
Thanks in advance.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2024 05:48 AM
One thing that you should do is use GlideAggregate rather than getRowCount(). getRowCount is ok for troubleshooting, but for actual code, you should avoid it as GlideAggregate is much faster and efficient. Here are some links to get you started.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2024 07:59 AM
Thank you Zach. I will try with the GlideAggregate and let you know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2024 09:17 AM
It's an expected behaviour, because the script is running synchronously. looking at the code, you are trying to update the records in another table, so I recommend trigger a flow and let the flow run asynchronously. You may also trigger an event and develop a script action to update the records