Scoped GlideRecord - getLastErrorMessage()

Retrieves the last error message. If there is no last error message, null is returned.

Table 1. Parameters
Name Type Description
None
Table 2. Returns
Type Description
String The last error message as a string.
// Setup a data policy where short_description field in incident is mandatory
var gr = new GlideRecord('incident');
gr.insert(); // insert without data in mandatory field
var errormessage = gr.getLastErrorMessage(); 
gs.info(errormessage);

Output: Data Policy Exception: Short description is mandatory