The CreatorCon Call for Content is officially open! Get started here.

Auto Creation of Table

t7
Tera Contributor

Hi Community , Can we auto create table with the help of script or anything ? 

1 ACCEPTED SOLUTION

Hello @t7 

 

HTML Code :-

 

<div class="panel panel-default">
 <div class="panel-heading">Templates</div>
 <div class="panel-body">
 <button type="button" class="btn btn-primary btn-block" ng-click="c.uiAction()">Create Table</button>
 </div>
</div>

 

 

Client Script :-

 

function() {
  var c = this;
	c.uiAction = function(action) {
		c.data.action = action;
		c.server.update().then(function() {
			c.data.action = undefined;
		})
	}
}

 

 

Server Script :-

 

(function() {
	

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();
	
})();

 

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Regards,

Samaksh

View solution in original post

4 REPLIES 4

Chetan Mahajan
Kilo Sage

Hello @t7 ,

                     refer this thread Can we create table using script? 

Kindly mark correct and helpful if applicable

t7
Tera Contributor

thanks for your help @Chetan Mahajan . Can we create a table with the help of widget?  Like after clicking on widget in any portal a table should be created in backend , can we achieve it anyhow?

Hello @t7 

 

HTML Code :-

 

<div class="panel panel-default">
 <div class="panel-heading">Templates</div>
 <div class="panel-body">
 <button type="button" class="btn btn-primary btn-block" ng-click="c.uiAction()">Create Table</button>
 </div>
</div>

 

 

Client Script :-

 

function() {
  var c = this;
	c.uiAction = function(action) {
		c.data.action = action;
		c.server.update().then(function() {
			c.data.action = undefined;
		})
	}
}

 

 

Server Script :-

 

(function() {
	

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();
	
})();

 

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Regards,

Samaksh

t7
Tera Contributor

Thank you so much @Samaksh Wani