- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2021 04:36 AM
Hi,
Let's say, I want to insert a new record with GlideRecord.insert in background script.
If object is inserted, the return value is a new object. OK.
If object is Not Inserted for any reason, the return value is null, and a message is displayed on background console. OK.
I would like to programmatically catch this error to display it or do something with.
Do you know how to do that ?
thanks.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2021 04:57 AM
you can use this function to get the error message from the gliderecord object of that table
Consider you are trying to insert some record and some BR is aborting the insert with some error message
Using this you can print that error message
gr.getLastErrorMessage();
OR
You can also use Try Catch block to print the exception message
try{
var gr = new GlideRecord("table");
gr.initialize();
gr.field1 = 'hello';
gr.insert();
}
catch(ex){
gs.info('Exception' + ex);
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2021 04:43 AM
Hi Bruno,
Can you please show us image which error you are talking about after background script failure?
Thank you
Prasad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2021 04:46 AM
I know I have an error with encryption. Message is :
Background message, type:error, message: Invalid attempt to insert non-encrypted data into field: u_xxxxx in table: cmdb_ci_appl.
But my question is : how can I catch this message programmatically to do something with ....
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2021 04:57 AM
you can use this function to get the error message from the gliderecord object of that table
Consider you are trying to insert some record and some BR is aborting the insert with some error message
Using this you can print that error message
gr.getLastErrorMessage();
OR
You can also use Try Catch block to print the exception message
try{
var gr = new GlideRecord("table");
gr.initialize();
gr.field1 = 'hello';
gr.insert();
}
catch(ex){
gs.info('Exception' + ex);
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2021 05:08 AM
Thanks Ankur, gr.getLastErrorMessage() do the job for me.