Can I create a custom table via a script?

Todd O
Tera Guru

Is it possible to create a SN custom table via a script? I would like to create many tables that are coming from a different database. I would like to write a script to read in that ddl and then translate that to whatever SN needs to create these tables. It will save me a lot of typing. Thank you in advance.

Todd

1 ACCEPTED SOLUTION

Here's an example of adding a new extended table and a column



// create a new table 'abc' by extending 'task' and add new string column 'myfield'


var table_name = 'abc', extends_table = 'task', fname = 'myfield';



var attrs = new Packages.java.util.HashMap();
var ca = new GlideColumnAttributes(fname);
ca.setType("string");
ca.setUsePrefix(false);
attrs.put(fname, ca);



var tc = new GlideTableCreator(table_name , table_name);
tc.setColumnAttributes(attrs);
if(typeof extends_table != 'undefined') tc.setExtends(extends_table);
tc.update();



You can run this in Background Script and go to System Definition > Tables or Tables & Columns to see the new table and column.


View solution in original post

20 REPLIES 20

Here is the current link: TableUtils - Global (servicenow.com)