1

I am trying to use a between operator as below,

curl -k "https://instance.service-now.com/api/now/table/My_Table?sysparm_query=sys_updated_on>javascript:gs.dateGenerate('2017-12-06','14:45:23')^sys_updated_on<javascript:gs.dateGenerate('2017-12-08','14:45:23')" --request GET --header "Accept:application/json" --user 'My Username':'My Password'

The output that I get is not in between the specified date Limit. Is there anything that I am doing wrong with the Command. Is the above command built correctly?I am stuck with this and trying different ways. Can anybody help me?

Pavan_Obj
  • 829
  • 7
  • 18

1 Answers1

1

I recommend using the BETWEEN query operator.

sysparm_query=sys_updated_onBETWEENjavascript:gs.dateGenerate('2017-12-06','14:45:23')@javascript:gs.dateGenerate('2017-12-08','14:45:23')

You should then URL-encode the query to make sure none of your characters would cause an issue:

sys_updated_onBETWEENjavascript%3Ags.dateGenerate(%272017-12-06%27%2C%2714%3A45%3A23%27)%40javascript%3Ags.dateGenerate(%272017-12-08%27%2C%2714%3A45%3A23%27)

Pro-tip: You can actually just go to the table and run the exact query you want to run, then right-click the query breadcrumb and click "Copy query" to get the exact query syntax you want.

More on this in my book: Learning ServiceNow. For a more advanced and shorter compendium of ServiceNow best-practices, pro-tips, and guidelines, check out my latest book: The ServiceNow Development Handbook.

Tim Woodruff
  • 560
  • 3
  • 8
  • Tim I have one doubt with this, What would be the Time Zone that ServiceNow use? – Pavan_Obj Mar 01 '18 at 00:37
  • This generates times in GMT - the system time-zone. Details on the gs.dateGenerate() API here: https://docs.servicenow.com/bundle/kingston-application-development/page/app-store/dev_portal/API_reference/GlideSystem/concept/c_GlideSystemAPI.html#ariaid-title18 Info on handling time-zones in ServiceNow in my article, here: https://snprotips.com/blog/2017/9/12/handling-timezones-in-servicenow-timezoneutil – Tim Woodruff Mar 02 '18 at 01:37
  • Thank you for your Response Tim. – Pavan_Obj Mar 02 '18 at 15:08
  • No problem. Please remember to mark as correct if this helped you out. – Tim Woodruff Mar 04 '18 at 00:36