Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Service Now API specify fields in CSV

Tags:

servicenow

I am trying to get a list of incidents from Service Now which is active. I just need a specific field called due_date from the data. If I use JSON

curl -s -L --user username:password --header "Accept: application/json" --header "Content-Type:application/json" "https://myservicenow.com/api/now/table/incident?sysparm_query=opened_atRELATIVEGE@dayofweek@ago@100"

I get a URL like

    {
        "active": "true",
        ......
        "due_date": "2015-07-22 07:07:28",

    }

I want to do the same thing using CSV web service. So I used

curl -s -L --user username:password "https://myservicenow.com/incident.do?CSV&sysparm_query=opened_atRELATIVEGE@dayofweek@ago@100"

I get fields like

"number","sys_created_by","caller_id","short_description","subcategory","u_subcategory_detail","category","priority","state","assignment_group","assigned_to","opened_at","resolved_at"

But the field due_date is not present. How can I specify the fields to retrieve in CSV format ?

like image 264
user1191140 Avatar asked May 14 '26 19:05

user1191140


1 Answers

The CSV unloader is dumping fields based on a UI View for the table in question. The fields that are present on the UI View are the ones that get included in your output. Since you have not explicitly specified a view, the "Default view" is used, just like if you were to load a list within the application without a sysparm_view URL parameter specified.

Here's what you can do:

  • Go to the instance and open the list for the table (e.g. /incident_list.do)
  • Modify your view via Personalize/Configure List to add the due_date column
    • Don't use the Cog-wheel list personalization, that won't actually change the view
  • Try your CSV pull again, you should have the due_date column included!

Now, if you don't actually want to change your default view, you can create a new UI View on the target table (give it a name like 'csv_dump'), and then add the parameter sysparm_view=csv_dump to your URL, thusly:

curl -s -L --user username:password "https://myservicenow.com/incident.do?CSV&sysparm_view=csv_dump&sysparm_query=opened_atRELATIVEGE@dayofweek@ago@100"

...passing the value for sysparm_view as whatever name you used to create your UI View.

like image 177
Joey Avatar answered May 19 '26 03:05

Joey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!