Stream.toArray() limits under 100?

Takaaki Sawai
ServiceNow Employee
ServiceNow Employee

Hi experts,

 

I would like to get 200 records as an array using GlideQuery, but I get the following error.

The following code executed.

var users = new global.GlideQuery('sys_user')
    .limit(10)
    .select('first_name', 'last_name')
    .toArray(101);  // Specify over 100
gs.info(JSON.stringify(users));

The following error message was displayed.

Stream.toArray expects a positive integer argument <= 100

 

Is this a specification that the number of records that can be retrieved as an array is limited to 100, i.e., limit() can only specify up to 100?

1 ACCEPTED SOLUTION

Tony Chatfield1
Kilo Patron

Hi, if you run your code in a PDI background window the stack trace includes the sys_id of the script-include involved

NiceError: [2023-01-30T02:55:48.366Z]: Stream.toArray expects a positive integer argument <= 100
-------- STACK TRACE ---------
at [global] 'Stream' [sys_script_include:9f50ba7773a31300bb513198caf6a791]:316 (toArray)
at [background script]:4
------------------------------

Looking at the function toArray() in the stream script-include

/nav_to.do?uri=sys_script_include.do?sys_id=9f50ba7773a31300bb513198caf6a791

The parameter has a hard coded limit and will only accept an integer between 1 and 100

 Stream.prototype.toArray = function toArray(count) {
if (!Schema.isMathematicalInteger(count) || count < 1 || count > 100) {
NiceError.raise('Stream.toArray expects a positive integer argument <= 100');
}

Stream | ServiceNow Developers

does not explain why this method has 100 defined as max for the parameter and I suspect you would need to log a case with NowSupport (or if you can directly engage the development team) for an explanation as to why the limit is set.

View solution in original post

3 REPLIES 3

SoniaShridhar13
Giga Guru

@Takaaki Sawai  addQuery would default to IN if you gave it an array. Please mark an answer correct to close the thread down.

Tony Chatfield1
Kilo Patron

Hi, if you run your code in a PDI background window the stack trace includes the sys_id of the script-include involved

NiceError: [2023-01-30T02:55:48.366Z]: Stream.toArray expects a positive integer argument <= 100
-------- STACK TRACE ---------
at [global] 'Stream' [sys_script_include:9f50ba7773a31300bb513198caf6a791]:316 (toArray)
at [background script]:4
------------------------------

Looking at the function toArray() in the stream script-include

/nav_to.do?uri=sys_script_include.do?sys_id=9f50ba7773a31300bb513198caf6a791

The parameter has a hard coded limit and will only accept an integer between 1 and 100

 Stream.prototype.toArray = function toArray(count) {
if (!Schema.isMathematicalInteger(count) || count < 1 || count > 100) {
NiceError.raise('Stream.toArray expects a positive integer argument <= 100');
}

Stream | ServiceNow Developers

does not explain why this method has 100 defined as max for the parameter and I suspect you would need to log a case with NowSupport (or if you can directly engage the development team) for an explanation as to why the limit is set.