- 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-06-2018 10:32 PM
Hi Tim,
Could you please explain your scenario? I suggest, creating tables from background script is not a good practice.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2018 11:00 PM
Hi hardit,
Here is my scenario:
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2018 11:35 PM
Hi Tim,
Try below code.
var gr= new GlideRecord('sys_db_object');
gr.newRecord();
gr.setValue('label','Computer ID1');
gr.setValue('name','u_computer_id1');
gr.setValue('super_class','353a302af822030059a64c78fda74add'); //sys_id of cmdb_ci
gr.insert();
var gr1= new GlideRecord('sys_dictionary');
gr1.newRecord();
gr1.setValue('name','u_computer_id1');
gr1.setValue('internal_type','747127c1bf3320001875647fcf0739e0');
//sys_id of string field type
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','747127c1bf3320001875647fcf0739e0');
//sys_id of String field type
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();
Hope it helps.
Mark it as helpful or correct if find helpful.
Regards,
Karishma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2018 09:17 PM
Hi Karishma,
I run above code in Scripts - Background but it show below error:
Operation against file 'sys_db_object' was aborted by Business Rule 'Table Field Validation^a95eaa714f22130004c3f9aba310c74d'. Business Rule Stack:Table Field Validation
Background message, type:error, message: is not currently marked as extensible
#### Compiler Stats ####
Compiles: 800, time: 4,762ms
Total classes: 800, bytecode length: 5,376,385
Total loaders created: 800, unloaded: 0, existing: 800
Interpreted compiles: 46, time: 84ms, total bytes: 60,792
Cache name: "syscache_expression", max: 8,192, size: 846, seeks: 347,461, hits: 345,759, misses: 1,702, flushed: 0, puts: 0
Table is not valid - u_computer_id1
Table is not valid - u_computer_id1
Thanks,
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2018 09:55 PM
Hi Tim,
Run the above code with the sys_id of cmdb_ci in sys_db_object table of your instance. And also check the sys_id of the string field type in sys_glide_object table. And use those sys_ids instead of the sys_ids I provided in the above code.
Regards,
Karishma