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

Can we create table using script?

Rajan Masurkar
Tera Contributor

Can anyone guide me whether we can create table using script?

Mraj

1 ACCEPTED SOLUTION

We can create UI action and can use below scrip.


Source table   is Assessment Metric



      Var cat_sys_id = current.sys_id.toString();


      var attrs = new Packages.java.util.HashMap();


      var table_name= 'custom_table';


      var fname;


      var src_table = new GlideRecord('asmt_metric');


      src_table.addQuery('category', cat_sys_id);


      src_table.query();


      while(src_table.next())


              {


              fname = src_table.name;


              var ca = new GlideColumnAttributes(fname);


              ca.setType("string");


              ca.setUsePrefix(true);


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


View solution in original post

5 REPLIES 5

snehabinani26
Tera Guru

Hi Rajan,



This link have steps to create a custom table from script.



Can I create a custom table via a script?



Hope this helps you


Karthik Reddy T
Kilo Sage

Hello Rajan,



Refer the below links may helpful to you.


Can I create a custom table via a script?  



  1. var table_name = 'abc', extends_table = 'task', fname = 'myfield';  
  2.  
  3. var attrs = new Packages.java.util.HashMap();  
  4. var ca = new GlideColumnAttributes(fname);  
  5. ca.setType("string");  
  6. ca.setUsePrefix(false);  
  7. attrs.put(fname, ca);  
  8.  
  9. var tc = new GlideTableCreator(table_name , table_name);  
  10. tc.setColumnAttributes(attrs);  
  11. if(typeof extends_table != 'undefined') tc.setExtends(extends_table);  
  12. tc.update();  


How to automatically create a target table for a data import set?


Karthik Reddy T.
ServiceNow Commnunity MVP -2018 class.

navdeep_singh
Giga Guru

Hi Rajan,



Yes, we can create a table by using script.



Please explain your requirement in detail.



Regards,


Navdeep


Hi Navdeep,



The requirement is columns of this table will be the records in other tables.



Mraj