How to delete multiple records in servicenow table using REST API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2020 09:07 PM
How to delete multiple records in servicenow table using REST API
- Labels:
-
Content Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2020 09:10 PM
Hi Gokulendra,
please find the link of the article https://community.servicenow.com/community?id=community_article&sys_id=66c5d6c61b03b748ada243f6fe4bc... it will help you.
Please mark correct if it solves your problem.
Thanks
Hemant
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2020 09:14 PM
Ok Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2020 09:18 PM
please mark my answer correct and helpful.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2020 09:18 PM
Hello,
When we integrate ServiceNow with other 3rd party systems, below are some of the common functionality that you do it
- Fetch (List)
- Create/Add
- Update/Modify
- Delete
In this article, I will show you the code on how you can do bulk delete through API.
As you aware, ServiceNow REST API allows you to delete 1 record at a time. So in order to delete bulk records, one way is to fetch all the records that you want to delete, loop through it and call delete API one by one. Below is the sample code snippet that allows you to do this.
var request = new sn_ws.RESTMessageV2();
//modify the end point as per your requirement. i just queried incidents whose assignment group is servicedesk. you can change as per your requirement.
request.setEndpoint('https://your-instance.service-now.com/api/now/table/incident?sysparm_query=assignment_group%3Dd625dccec0a8016700a222a0f7900d06&sysparm_fields=number%2Cshort_description%2Csys_id');
request.setHttpMethod('GET');
//UPDATE AS PER YOUR INSTANCE CREDENTIALS BELOW.
var user = 'admin';
var password = 'admin';
request.setBasicAuth(user,password);
request.setRequestHeader("Accept","application/json");
var response = request.execute();
var result = response.getBody();
var result_json = JSON.parse(result);
//now loop through the results and call delete API
for(i=0;i<result_json.result.length;i++) {
//call delete API
request.setEndpoint('https://your-instance.service-now.com/api/now/table/incident/'+result_json.result[i].sys_id); //change end point as per your table
request.setHttpMethod('DELETE');
request.setRequestHeader("Accept","application/json");
response = request.execute();
gs.info("Record is deleted successfully"+result_json.result[i].number);
}
If you have any questions, let me know in the comments section.
Mark the article as helpful and bookmark if it finds useful.