Provide year filter in sysparams in a table REST API

ashwinipingle
Tera Guru

Dear All,

I want to set up parameters for a table and access this as a REST API.

For this, I want to set a filter in sysparams as 'where table-column = to_year(sysdate)'  -- so i want to filter all the records of the table where column value is same as the current year.

How can i provide this sysparams?

 

Best Regards,

Ashwini Pingle

2 REPLIES 2

SwarnadeepNandy
Mega Sage

Hello,

 

To provide the sysparams for your filter, you need to use the sysparm_query parameter and encode your query using the ServiceNow query syntax. For example, if you want to filter all the records of the incident table where the opened_at column value is the same as the current year, you can use this sysparm_query:

 

sysparm_query=opened_atONThis%20year@javascript:gs.dateGenerate('','')

 

This will encode the query 

 

opened_atONThis year@javascript:gs.dateGenerate('','')

 

which means that the opened_at date is on this year.

You can also use other operators and functions to create more complex queries. You can find more information about the query syntax and how to encode it here.

 

Kind Regards,

Swarnadeep Nandy

Thanks a lot for your response. I tried the javascript as follows and was able to provide the year parameter in the sysparams

https://instancename.service-now.com/api/now/table/custtablename?sysparm_query=u_calendar_year%3Djav...

 

I could also do a year+1 filter

https://instancename.service-now.com/api/now/table/custtablename?sysparm_query=u_calendar_year%3Djav...