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 04:13 PM
Shloke04,
user did iterate by using gr.next() in line number 7. I used the same script and changed the encoded query, and i deleted a row from the discovery_range_item table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2018 08:41 AM
Aman,
Yes, I am able to delete from discovery_range_item without a script using the web UI. Going to reach on to the internal ServiceNow support team to look at System Logs -> System Log -> Errors/All.
Is there a way to capture an error message in the script?
Thank you,
CoyoteRay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2018 10:04 AM
You can capture the error in scripts using try catch statements, but given your situation, you cannot. because to use try catch statements, your code should bomb due to the error and stop the executing(Like a real error).
Lets wait and see what the system logs say.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2018 07:16 AM
Good Day,
On line 7 there is a gr.next(). This script is the simplest form for testing, get a (1) record and try to delete it. I put the deleteRecord in a loop for testing, got the same result - the record remains.
Thank you for the reply.
CoyoteRay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2018 10:12 AM
Had to set "Can delete" on table (discovery_range_item) to true. Still not clear as to why there was not error message or log indicating there were permission issues.
The ServiceNow support team was great help.