Scripted REST API - sysparm_limit & sysparm_offset

Mussie
ServiceNow Employee
ServiceNow Employee

Hi Guys,

I know what they mean in theory but I am trying to find a working example of the usage of sysparm_offset and sysparm_limit? Does anybody have one?

Mussie

1 ACCEPTED SOLUTION

srinivasthelu
Tera Guru

Hi Mussie,




Those parameters have some meaning only for table apis. Out of the the box API's. In case if you are implementing a Scripted Web Service, You can choose to have different parameter names to achieve the same.



GlideRecord API has below method which you can use to achieve the same behaviour. Grab those parameters and pass it to below function


chooseWindow(Number f, Number l, Boolean forceCount)

Sets a range of rows to be returned by subsequent queries.


Parameters:


  • f - (Number) the first row to include.
  • l - (Number) the last row to include.
  • forceCount - (Boolean) if true the getRowCount() method will return all possible records.

Returns:


void

Example:



var gr = new GlideRecord('incident'); gr.orderBy('number'); gr.chooseWindow(2, 4); gr.query(); if (gr.next()) { gs.info(gr.number + ' is within window'); }


Output:


INC0000002 is within window

View solution in original post

5 REPLIES 5

srinivasthelu
Tera Guru

Mussie
ServiceNow Employee
ServiceNow Employee

Thank you both for your responses. Yes, I have already seen these pages, I already have a scripted rest api which pulls records from ServiceNow table and what I am after is, where do I stick these parameters?


Mussie


srinivasthelu
Tera Guru

Hi Mussie,




Those parameters have some meaning only for table apis. Out of the the box API's. In case if you are implementing a Scripted Web Service, You can choose to have different parameter names to achieve the same.



GlideRecord API has below method which you can use to achieve the same behaviour. Grab those parameters and pass it to below function


chooseWindow(Number f, Number l, Boolean forceCount)

Sets a range of rows to be returned by subsequent queries.


Parameters:


  • f - (Number) the first row to include.
  • l - (Number) the last row to include.
  • forceCount - (Boolean) if true the getRowCount() method will return all possible records.

Returns:


void

Example:



var gr = new GlideRecord('incident'); gr.orderBy('number'); gr.chooseWindow(2, 4); gr.query(); if (gr.next()) { gs.info(gr.number + ' is within window'); }


Output:


INC0000002 is within window