- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2018 08:06 PM
Hello,
I want to create table with two column as below setting using script:
Table Label: Computer ID
Table Name: u_computer_id
Extends table: Configuration Item
Column label: Computer NameType: StringMax length: 90Column name: u_computer_name
Column label: TypeType: StringMax length: 32
Default value: Exports to::Imports from
Display: trueColumn name: u_type
How to create above table using script in ServiceNow Scripts - Background?
Thanks,
Tim
Solved! Go to Solution.
- Labels:
-
Operational Intelligence
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2018 02:49 AM
Hi Tim,
Good to know its working. Please mark it as correct, if you are satisfied with the solution and close this thread.
Regards,
Karishma

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2018 10:49 PM
I think, you have to make sure the Extensible field in cmdb_ci table is checked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2018 12:28 AM
Hi Karishma,
I run below code in Scripts - Background,it can create a table with two column but it doesn't add Configuration Item in Extends table(refer to attachment file)
How to create a table with Extends table: Configuration Item?
Thanks,
Tim
var gr= new GlideRecord('sys_db_object');
gr.newRecord();
gr.setValue('label','Computer ID1');
gr.setValue('name','u_computer_id1');
gr.setValue('super_class','Configuration Item');
gr.insert();
var gr1= new GlideRecord('sys_dictionary');
gr1.newRecord();
gr1.setValue('name','u_computer_id1');
gr1.setValue('internal_type','String');
gr1.setValue('column_label','Computer Name');
gr1.setValue('element','u_computer_name');
gr1.setValue('max_length','90');
gr1.insert();
var gr2= new GlideRecord('sys_dictionary');
gr2.newRecord();
gr2.setValue('name','u_computer_id1');
gr2.setValue('internal_type','String');
gr2.setValue('column_label','Type');
gr2.setValue('element','u_type');
gr2.setValue('max_length','32');
gr2.setValue('display','true');
gr2.setValue('default_value','Exports to::Imports from');
gr2.insert();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2018 12:51 AM
Hi tim,
Go through the modifications mentioned below in bold.
var gr= new GlideRecord('sys_db_object');
gr.newRecord();
gr.setValue('label','Computer ID1');
gr.setValue('name','u_computer_id1');
gr.setValue('super_class','Configuration Item');
// Since it's a Reference field it will accept sys_id. Hence, Instead of using "Configuration Item" use the hard coded sys_id of the "cmdb_ci " in sys_db_object table. Copy the sys_id of that record and paste it here.
gr.insert();
var gr1= new GlideRecord('sys_dictionary');
gr1.newRecord();
gr1.setValue('name','u_computer_id1');
gr1.setValue('internal_type','String'); // internal_type field is a reference field which will accept sys_id. Hence insted of using "string" in the query pass the hard coded sys_id. Copy the sys_id of the "string" field record in "sys_glide_object" table and use it here.
gr1.setValue('column_label','Computer Name');
gr1.setValue('element','u_computer_name');
gr1.setValue('max_length','90');
gr1.insert();
var gr2= new GlideRecord('sys_dictionary');
gr2.newRecord();
gr2.setValue('name','u_computer_id1');
gr2.setValue('internal_type','String'); // internal_type field is a reference field which will accept sys_id. Hence insted of using "string" in the query pass the hard coded sys_id. Copy the sys_id of the "string" field record in "sys_glide_object" table and use it here.
gr2.setValue('column_label','Type');
gr2.setValue('element','u_type');
gr2.setValue('max_length','32');
gr2.setValue('display','true');
gr2.setValue('default_value','Exports to::Imports from');
gr2.insert();
Regards,
Karishma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2018 02:27 AM
Hi Karishma,
It can show Configuration Item in Extends table after using sys_id of the "cmdb_ci " in sys_db_object table.
Thanks a lot.
Thanks,
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2018 02:49 AM
Hi Tim,
Good to know its working. Please mark it as correct, if you are satisfied with the solution and close this thread.
Regards,
Karishma