.insert() is not working

bishalsharm
ServiceNow Employee
ServiceNow Employee

Hi Team,

 

A simple GlideRecord code is taking infinity time to insert a new record into a custom table

I gave the sufficient role to logged in user to validate the create ACL but no luck

 

any idea on this ?

1 ACCEPTED SOLUTION

Simon Christens
Kilo Sage

It could also have to do with Business rules on that table.

Can be tested by deactivating BRs on insert

var newRecordGR = new GlideRecord('table_name');
newRecordGR.newRecord();
newRecordGR.setValue('field_name', 'value');
newRecordGR.setWorkflow(false); //Disables running BRs when inserting the record
newRecordGR.insert();

If theres alot of BRs running, doing all kinds of weird stuff it might increase the time it takes overall

View solution in original post

9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

@bishalsharm 

is it taking long for all records?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Ankur Bawiskar 

Didn't get you when you said all records ?

It is taking long time and went on infinite loop when I am simply inserting record.

sample scriipt

var newRecordGR = new GlideRecord('table_name');

field1 = 'value';

newRecordGR.insert()

@bishalsharm 

how it behaves when you insert manually?

Also you are not using initialize() method?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Chaitanya ILCR
Kilo Patron

Hi @bishalsharm ,

sample insert code

var gr = new GlideRecord("table_name");
gr.initialize(); //or you can use newRecord() inplace of initialize()
gr.field_name = 'value'; //field_name is field on your table
gr.insert();

you need to use initialize() or newRecord() method on the GlideRecord object first and set the field values and use the insert() after the field are set

 

order

 

  1. initialize or newRecord
  2. set fields
  3. insert 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya