About background script limitations.

Ajay95
Tera Contributor

Hi,

 

I was running a simple background script to get the sys_id of each record in the table. But I am able to get only 50000 sys_id only even though the table has the more than 1 lac records.

 

Can any one tell me is there any limitation that how many records can be fetched in background script at a time?

 

 

Below is the script I am using for reference:

 

var gr = new GlideRecord("sys_user_grmember");

gr.query();

while(gr.next()){

gs.print(gr.sys_id);

1 ACCEPTED SOLUTION

Samaksh Wani
Giga Sage
Giga Sage

Hello @Ajay95 

 

It may happens due to linear search of records, as it is quite time consuming. so it is showing only 50K records,

 

You need to Apply the bg script 2 times :-

 

gr.setLimit(50000); // First 50K records.

gr.chooseWindow(50000, 100000);  // For next 50K Records.

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Regards,

Samaksh

View solution in original post

5 REPLIES 5

Nayan  Dhamane
Kilo Sage
Kilo Sage

Hello @Ajay95 ,

 

Try creating a scheduled job and return the same output in a log.

 

If my answer solved your issue, please mark my answer as Correct & Helpful based on the Impact

Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.

Hi Nayan 

 

Thanks for the reply.

 

But is it the limitation of background script to return 50k records only at a time.

Hello @Ajay95 ,

Yes as background scripts run on the server it takes time to load and query all the records. Hence the action might be aborted based on it.

 

If my answer solved your issue, please mark my answer as Correct & Helpful based on the Impact

Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.

Samaksh Wani
Giga Sage
Giga Sage

Hello @Ajay95 

 

It may happens due to linear search of records, as it is quite time consuming. so it is showing only 50K records,

 

You need to Apply the bg script 2 times :-

 

gr.setLimit(50000); // First 50K records.

gr.chooseWindow(50000, 100000);  // For next 50K Records.

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Regards,

Samaksh