insert() not working after initialize.

tahnalos
Kilo Sage

Trying to insert a new record using a string that contains a sys_id obtained through a third party process.   The sys_id exists on the table being referred to but I can't seem to get the insert to work.   Both u_sector and u_eq_detail are reference fields, and sector is itself passed into the function in question.   The following code is in a non client-callable script include:

var gr1 = new GlideRecord ('u_sec_eq_rel');

var gr2 = new GlideRecord ('u_ss_equipment_detail');

gr1.initialize();

gr2.get('string sys id from third party app');

gr1.u_sector = sector;

gr1.u_eq_type = eq_type;

gr1.u_eq_detail = gr2.sys_id;

gr1.u_quantity = 1;

gr1.insert(); <== error occurs here.

I keep getting this error: org.mozilla.javascript.EcmaError: 3 is not a function.

Whereas the number referred to is random.

Ideas?

15 REPLIES 15

Use this code



var gr1 = new GlideRecord ('u_sec_eq_rel');


gr1.initialize();


gr1.u_sector = sector;


gr1.u_eq_type = eq_type;


var gr2 = new GlideRecord ('u_ss_equipment_detail');


if(gr2.get('string sys id from third party app'))


  gr1.u_eq_detail = gr2.sys_id;


gr1.u_quantity = 1;


gr1.insert();


I don't think its the get that's the issue.   To test this, I removed the get and tried again.   Same problem.



The question I have is what does an error during the insert line usually mean?



Thanks


Where is 'sector' defined? Can you post the entire code


Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

It seems that this isn't the whole script, is that correct? is it possible we can see the whole script?


//Göran


tahnalos
Kilo Sage

I'm not sure how posting the entire code will help (considering that I am told not to divulge too much of it).



Even if I comment out all the lines that define gr1 and just do gr1.insert(), it's still causing me a problem.



What does the error line: 'org.mozilla.javascript.EcmaError: 3 is not a function' mean?