3

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 ?

user1191140
  • 1,559
  • 3
  • 18
  • 37

1 Answers1

4

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.

Joey
  • 2,901
  • 21
  • 22
  • Where, exactly is the Personalize menu? I'm at /wm_order_list.do and can't find anything that says Personalize except the cog wheel. – tolsen64 Aug 26 '19 at 19:07