Saturday, March 15, 2014

ServiceNow – Why is GlideRecord insert() returning a null



You’re trying to save your spiffy new record but var incSid = current.insert() is returning null.  Boo. 

To make matters more fun, this code is an Inbound Email Action.  One might suspect that the guy responsible for anything with the letters e-m-a-i-l in ServiceNow must really like creating puzzles or hate wasting disk space on silly things known as error messages.

The first thought is that it could be an ACL issue.  You don't have create rights to the table so that must be why it is failing.  The only problem with that theory is that you are an admin and  so theoretically the code is running in your authorization context.

So what now?  Bad data maybe?  Ok, so off to our friend 'Background Scripts'.  Let's try a field that doesn't exist
var x = new GlideRecord('incident');
x.u_something_that_cant_exist = true;

gs.log(x.insert());
Well, that returned a sys_id and not null. But it did seem to return some log messages.

So, this was a fruitful path to investigate. I went ahead and replaced incident with the table in question and voila, we get an error message when running the background script:
Background message, type:error, message: Data Policy Exception:  user is mandatory 
*** Script: null
and there we go. The problem was that it wasn't a bad field but missing data in a mandatory field.

No comments: