System becomes unresponsive while updating 33k records

Shankha
Tera Contributor

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.

3 REPLIES 3

Zach Koch
Giga Sage
Giga Sage

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.

Docs page 

Understanding GlideAggregate 

 

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!

Thank you  Zach. I will try with the GlideAggregate and let you know. 

amaradiswamy
Kilo Sage

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

https://docs.servicenow.com/bundle/xanadu-platform-administration/page/administer/platform-events/re...