The CreatorCon Call for Content is officially open! Get started here.

insert() method returning null

Nisar2
Mega Guru

Hi experts,

A strange behaviour is driving me nuts. I've the following code inside a SI

var task = new GlideRecord('u_my_table');
task.initialize();
task.u_name = "Test";
var sys_id = task.insert();
gs.log(sys_id, "ABC");

The problem here is two fold:

  1. Logs print the sys_id as null 1 in 50 tries (just a calculated guess)
  2. Logs print the sys_id as expected the remaining times

So, I wonder what is causing it to fail that one time and if it is possible to know the reason why it failed?

I tried looking at logs (during the timeframe at which the insert happened) and did not find any warning/error level data.

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Nisar,

It's strange.

Do you have any before insert BR on that table or any data policy applied on that table.

Ideally it should give you the sys_id everytime.

If that is the case please raise a HI ticket with ServiceNow if this is for your client instance.

Do let us know the updates.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

15 REPLIES 15

you can just log a if condition 

var task = new GlideRecord('u_my_table');

 task.newRecord(); // Try changing it to newRecord()

task.u_name = "Test";

var sys_id = task.insert();

if(!sys_id )

gs.log(task.u_name +"SysId: "+ sys_id )

 

--and can cehck for which name value it is givingn null value and then try creating the same record from background scripts, might get some hint.

 

Sudhanshu Talw1
Tera Guru

One in 50 tries!Looks like Servicenow is unhappy.

 

Although it should return sys_id every time.

Record is getting created or not?

 

When it returns null

 

Thanks

Sudhanshu

No, record is not getting created when null is received.

andymcdonald
Kilo Guru

I just came across similar behavior today.  Mine happens with the cmdb_rel_ci table on Orlando, and yes, the record ALWAYS gets created successfully!  Have you opened a HI ticket yet?

Hitoshi Ozawa
Giga Sage
Giga Sage

The problem may be high load on your instance. Better contact HI and ask for their help.