What error caused deleteRecord to fail
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2018 12:42 PM
Good Day,
Forgive me if this was already answered, I am new to a ServiceNow development role.
I have a query that runs successfully in a scoped application and it returns the correct number of records. A call to deleteRecord fails (returns false) however there is no error message captured. Is there a place to capture why the delete failed? My account has access to delete from the web UI.
Below is the code for reference:
gs.info("Started"); var gr = new GlideRecord('discovery_range_item'); gr.addEncodedQuery('nameSTARTSWITH15.15.15.15'); gr.query(); gs.info("Pulled " +gr.getRowCount() + " records."); gr.next(); var rtn = gr.deleteRecord(); gs.info("Return from deleteRecord: " +rtn); var errormessage = gr.getLastErrorMessage(); gs.info("Error message: " +errormessage); gs.info("Finished:");
Log reads:
Started Pulled 1 records Returned from deleteRecord: false Error message: null Finished
- Labels:
-
Personal Developer Instance

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2018 02:55 PM
hi there,
have you try look at System Logs -> System Log -> Errors/All?
hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2018 08:37 AM
Thank you, will get with the internal ServiceNow team to look at those - I don't have access 😞
Is there a way to capture the error message within the script? If so, can you point me in the right direction?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2018 06:50 AM
We could not find any errors or logs as to why the deleteRecord failed. When a colleague runs the script the record is removed as expected. My ServiceNow Administrator is looking to why this is failing, will reply once we find the cause.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2018 03:35 PM
Hi,
According to your query, I don't see where you are iterating the loop after deleting your First Record. You are getting the count correct initially but after that once the First Record is deleted it needs to be iterated to go to the Second Record based on your Encoded Query for Deletion. Please use the below Script which should work for you:
Script:
var gr = new GlideRecord('discovery_range_item');
gr.addEncodedQuery('nameSTARTSWITH15.15.15.15');
gr.query();
while(gr.next()){
gr.deleteRecord();
}
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke