How do you handle gs.addErrorMessage in a non-interactive session?

MatthewPinheiro
Tera Contributor

I've noticed that many built-in business rules in ServiceNow, after aborting a record insert/update, will call gs.addErrorMessage() to tell the user why the operation failed. 

 

This is great in an interactive session where a real user sitting in front of their screen triggers the rule and so they can see the error message in real time, but gs.addErrorMessage() doesn’t seem to do anything if called in a non-interactive session.

 

So if I’m running a scripted REST API or some scheduled process or something, and that process ends up triggering one of those built-in business rules and ends up aborting, how am I supposed to programmatically get the error message, e.g. so my code can analyze the failure and decide to do something else? It seems like in those scenarios, the error just disappears and I can't find it at all.

2 REPLIES 2

MatthewPinheiro
Tera Contributor

Been a few days. I feel like I can't be the only one to face this issue, unless we're missing something about how we're supposed to handle errors at all?

Roger1
Tera Contributor

Not the most elegant solution, but I would add a gs.error() after the  gs.addErrorMessage().