Skip to content

Commit 290e6f0

Browse files
authored
Create Dynamic Table Creation.js
Normally, creating a new table means going through multiple steps in ServiceNow's interface. With this script, you can automate the process to quickly set up a new table with the exact columns you need. It’s useful when you need to frequently create similar tables, or you’re setting up a new application that requires multiple tables with specific fields.
1 parent 20569ab commit 290e6f0

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
(function() {
2+
var tableName = 'u_custom_table';
3+
var tableLabel = 'Custom Table';
4+
var tableDesc = 'Dynamically created table';
5+
var tableSysId = GlideTableDescriptor.createTable(tableName, tableLabel, tableDesc);
6+
7+
var col1 = new GlideColumnDescriptor('u_name', tableSysId);
8+
col1.setLabel('Name');
9+
col1.setType('string');
10+
col1.setMaxLength(100);
11+
col1.create();
12+
13+
var col2 = new GlideColumnDescriptor('u_description', tableSysId);
14+
col2.setLabel('Description');
15+
col2.setType('string');
16+
col2.setMaxLength(255);
17+
col2.create();
18+
19+
gs.print("Table created with sys_id: " + tableSysId);
20+
})();

0 commit comments

Comments
 (0)