How to fetch specific columns in response using scripted rest api?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2022 02:05 AM
Hi All,
I am able to produce all fields from table using scripted rest api. What is the code or syntax to fetch some specific columns only?
Thanks,
Tara
- Labels:
-
Change Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2022 02:10 AM
Hi tara
Can you share the code you tried to get all fields.
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2022 02:12 AM
Hi Tara,
If you are using get method you have an option in REST API explorer as shown below:
Response:
Code will look like this:
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('https://dev64130.service-now.com/api/now/table/sn_hr_core_case?sysparm_fields=state%2Csys_created_by&sysparm_limit=1');
request.setHttpMethod('GET');
//Eg. UserName="admin", Password="admin" for this code sample.
var user = 'admin';
var password = 'admin';
request.setBasicAuth(user,password);
request.setRequestHeader("Accept","application/json");
var response = request.execute();
gs.log(response.getBody());
Thanks,
Prashant
Please mark my answer Correct & helpful if its gives your solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2022 02:14 AM
Code will look like this:
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('https://dev64130.service-now.com/api/now/table/sn_hr_core_case?sysparm_fields=state%2Csys_created_by&sysparm_limit=1');
request.setHttpMethod('GET');
//Eg. UserName="admin", Password="admin" for this code sample.
var user = 'admin';
var password = 'admin';
request.setBasicAuth(user,password);
request.setRequestHeader("Accept","application/json");
var response = request.execute();
gs.log(response.getBody());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2022 10:04 PM
Hi Tara,
Please mark my answer correct and helpful if it resolved your issue.
Thanks,
Prashant