The CreatorCon Call for Content is officially open! Get started here.

Using sysparm_query with Incident table

thedavegray
Giga Expert

Hi all, 

 

Can I please get some starter advice on using the query parameter sysparm_query on the Incident table. 

 

Is it possible to get a date range based upon the sys_created_on field? So for example I would like to get just elements that match sys_created_on>=2022-01-21 AND <2022-01-22, I tried this but it does not work, it returns 

elements for 23rd, 24th etc,

 

sys_created_on%3E%3D2022-01-21&sys_created_on%3C2022-01-22

 

On the understanding that %3E%3D is >= and %3C is < (less than). 

 

Is it not possible to use multiple parameters with sys_created_on?

 

Screenshot of query running in Postman with values greater that 

 

thedavegray_0-1674573350666.png

 

Thanks 

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Basheer
Mega Sage

It should be like this

sys_created_on>javascript&colon;gs.dateGenerate('2022-01-22','00:00:00')^sys_created_on<javascript&colon;gs.dateGenerate('2022-01-23','23:59:59')

 

Full link should be like this

 

https://instanceName.service-now.com/incident_list.do?sysparm_query=sys_created_on%3Ejavascript%3Ags...

Please hit like button if my suggestion has helped you in any way.
Please mark correct if my response has solved your query.

Cheers,
Mohammed Basheer Ahmed.

View solution in original post

10 REPLIES 10

Hi @Basheer 

 

Even just using a greater than date with sysparm_query does not seem to work for me. For example, this url which should filter dates only for this year : 

 

https://company.service-now.com/api/now/table/incident?sysparm_query=sys_created_on>javascript%26col...

 

However a distinct list of the first 1000 elements gives these sys_created_on dates: 

 

  • 2019-06-12
    2019-06-13
    2019-06-14
    2019-06-15
    2019-06-16
    2019-06-17

 

I might post this as a new question as I already marked this one as answered. 

 

Thanks 

DrewW
Mega Sage

The easiest way to get the query you need is to go to the incident list, filter the list the way you want and then right click on the last part of the filter and select copy query.  Then just past that into the box you have for sysparm_query.  It should work just fine.

 

Hi @DrewW & @Hayo Lubbers 

 

I have filtered the incident list as you both mention on created > 30 days and created < today, or at least that's what I think it now says. This is what the sysparm_query param looks like now

 

sysparm_query%3Dsys_created_on%253Ejavascript%3Ags.beginningOfLast30Days()%255Esys_created_on%253Cjavascript%3Ags.beginningOfToday()%26sysparm_first_row%3D1%26sysparm_view%3D 

 

I'm not sure where the sysparm query now ends if I'm honest as my "&" query param delimiters have now gone.   Seems like sysparm_first_row and sysparm_view are part of the view formatting for the incident list, not really sure they would work as part of the REST call. 

 

Thanks 

Hi @thedavegray,

Even without the sysparm_first_row and sysparm_view your url would work. Those are present in the url to decide the first record of table and data view from which they need to be taken.

 

These will be useful when we are trying to send the data in chunks then you can set the offset(5000), firstrow(1st row 0 for 1st call, 1st row 5000 for next call and so on)

 

Please hit like button if my suggestion has helped you in any way.
Please mark correct if my response has solved your query.

Cheers,
Mohammed Basheer Ahmed.

Hi @Basheer 

 

Ah, I was going to ask about paging in a separate forum post.  

So basically it would be along the lines of. 

 

sysparm_first_row=1&sysparm_limit=1000

then 

sysparm_first_row=1001&sysparm_limit=1000

 

etc? 

 

I was going to run my consumer every day and collect elements that are perhaps under two days for insert or update into SQL.   

 

Thanks