Pavan_Obj
Pavan_Obj

Reputation: 1129

ServiceNow Rest API call

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?

Upvotes: 1

Views: 2149

Answers (1)

Tim Woodruff
Tim Woodruff

Reputation: 601

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.

Upvotes: 1

Related Questions