- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2017 04:11 AM
Hello Ladies and Gentlmen,
I have a table call 'u_test' and there are the fields 'field_one' and 'field_two',
i would like to write a script that will create a row in this table with 'field_one' and 'field_two' fill.
My current attempt was with:
var database = new GlideRecord('u_test');
database.initialize();
database.field_one='hello';
database.field_two=4;
database.insertWithReferences();
But it only create a record without any value in the 'field_one' and 'field_two'.
Maxime NGUYEN.
----------------------------
Re all: Thanks for all your answer,
Sorry for all your trouble, i'm embarassed, actually there isn't any error in the script itself, it was just me who had put caps without noticed it.
Message was edited by: Maxime NGUYEN
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2017 04:50 AM
Also make sure you use the name of field not label.
Thanks,
Shamma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2017 04:27 AM
Hi,
'field_one' is string 'field_two' is integer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2017 04:29 AM
Hi Maxime,
Here is the script to insert new record. Be careful to populate the value based on the field types i.e. if it is a reference field then you need to give sys_id etc
var tableRec = new GlideRecord('u_test');
tableRec.initialize();
tableRec.field_one = ''; // give correct value based on field type
tableRec.field_two = ''; // give correct value based on field type
tableRec.insert();
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2017 04:41 AM
Hi,
It stills add a row without any value in it.
Regards,
Maxime.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2017 05:05 AM
Re: Actually you were right I just noticed something that were my own error, actually the script that i gave to you was correct.
Regards,
Maxime.