What error caused deleteRecord to fail

CoyoteRay1
Tera Contributor

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
9 REPLIES 9

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. 

 

CoyoteRay,
 
Do you have enough permissions to delete records from discovery_range_item table ? Can you delete them manually without scripts? 
There might be something that is restricting you to delete the records
 
Thank you,
 
Aman Gurram

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

 

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.

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

CoyoteRay1
Tera Contributor

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.