
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2019 11:35 PM
Hi
In order to create a new target table, I have to first create table (50) columns in ServiceNow manually.
I want to know if I can create columns automatically in target table. My excel sheet data has nothing to do with task table columns or any other OOB table columns. So, inheriting the parent table is not the solution.
Please suggest me if there is any automation or configuration available for creation of multiple columns in ServiceNow.
Solved! Go to Solution.
- Labels:
-
Field Service Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2019 11:40 PM
What are the types of all columns that you need to create?
vat tables = [
{ "name" : "table1", fields : [
{"name" : "field1", "type": "string"},
{"name" : "field1", "type": "string"},
]},
];
Then you can run a script in the background to create the tables:
for (var i = 0; i < tables.length; i++){
var table = new GlideRecord('sys_db_object');
table.initialize();
table.name = tables[i].name;
tableSysID = table.insert();
var fields = tables[i].fields;
for (var j = 0; j < fields.length; j++){
var field = new GlideRecord('sys_dictionary');
field.initialize();
field.name = tableSysID;
field.column_label = fields[j].name;
field.internal_type = fields[j].type;
field.insert();
}
}
Thanks,
Abhishek
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2019 11:40 PM
What are the types of all columns that you need to create?
vat tables = [
{ "name" : "table1", fields : [
{"name" : "field1", "type": "string"},
{"name" : "field1", "type": "string"},
]},
];
Then you can run a script in the background to create the tables:
for (var i = 0; i < tables.length; i++){
var table = new GlideRecord('sys_db_object');
table.initialize();
table.name = tables[i].name;
tableSysID = table.insert();
var fields = tables[i].fields;
for (var j = 0; j < fields.length; j++){
var field = new GlideRecord('sys_dictionary');
field.initialize();
field.name = tableSysID;
field.column_label = fields[j].name;
field.internal_type = fields[j].type;
field.insert();
}
}
Thanks,
Abhishek
Abhishek Gardade

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2019 12:28 AM
Cool Abhishek! This is what I was looking for. Can you please help me with providing a link to play with arrays in ServiceNow ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2020 08:26 AM
I need to do something similar, however, the table is already created.
The fields I need to create are already on another table (scoped) and I want to replicate them in the new table, so I would like to read the current fields, build out the field JSON to replicate the fields and add them to the table. Again, the table already exists.
What are the possible items for the field JSON. You show name and type, how about ref qualifier, reference and all the other items that I can use to create the field(s).
Thanks in advance.