<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question How to clone a table in SysAdmin forum</title>
    <link>https://www.servicenow.com/community/sysadmin-forum/how-to-clone-a-table/m-p/2409422#M1648</link>
    <description>&lt;P&gt;I want to duplicate a table with identical fields within the same instance.&lt;/P&gt;&lt;P&gt;You can use the same fields with an extended table, but you don't want the child table's records to appear in the parent table.&lt;/P&gt;&lt;P&gt;There are nearly 80 fields that I plan to create in the table, so it's tough to manually duplicate them.&lt;/P&gt;&lt;P&gt;Anyone know how to clone a table?&lt;/P&gt;</description>
    <pubDate>Thu, 08 Dec 2022 15:27:13 GMT</pubDate>
    <dc:creator>bonsai</dc:creator>
    <dc:date>2022-12-08T15:27:13Z</dc:date>
    <item>
      <title>How to clone a table</title>
      <link>https://www.servicenow.com/community/sysadmin-forum/how-to-clone-a-table/m-p/2409422#M1648</link>
      <description>&lt;P&gt;I want to duplicate a table with identical fields within the same instance.&lt;/P&gt;&lt;P&gt;You can use the same fields with an extended table, but you don't want the child table's records to appear in the parent table.&lt;/P&gt;&lt;P&gt;There are nearly 80 fields that I plan to create in the table, so it's tough to manually duplicate them.&lt;/P&gt;&lt;P&gt;Anyone know how to clone a table?&lt;/P&gt;</description>
      <pubDate>Thu, 08 Dec 2022 15:27:13 GMT</pubDate>
      <guid>https://www.servicenow.com/community/sysadmin-forum/how-to-clone-a-table/m-p/2409422#M1648</guid>
      <dc:creator>bonsai</dc:creator>
      <dc:date>2022-12-08T15:27:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to clone a table</title>
      <link>https://www.servicenow.com/community/sysadmin-forum/how-to-clone-a-table/m-p/2409481#M1650</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/398642"&gt;@bonsai&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;You can use below script in background script&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The first argument is the source table, the table to be copied. The second argument is the new/target table. The third argument is Boolean: set it to false if you don't want to or need to create the indexes.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;cpTable('incident', 'incident_copy', true);
 
function cpTable(strOldTable, strNewTable, bCopyIndexes) {
    var tu = new TableUtils(strNewTable);
    var bNewTableAlreadyExists = tu.tableExists();
    if (bNewTableAlreadyExists) {
        gs.print("WARNING: Target Table " + strNewTable + " already exists!  Please choose a new target table name");
    } else {
        var gr = new GlideRecord(strOldTable);
        gr.initialize();
        var td = GlideTableDescriptor.get(strOldTable);
        var tdNewTable = new TableDescriptor(strNewTable, gr.getLabel());
        var dbo = new GlideRecord("sys_db_object");
        dbo.addEncodedQuery("super_classISNOTEMPTY^name=" + strOldTable);
        dbo.setLimit(1);
        dbo.query();
        if (dbo.next()) {
            tdNewTable.setExtends(dbo.super_class + '');
        }
        tdNewTable.setFields(gr);
        tdNewTable.copyAttributes(td);
        tdNewTable.setRoles(td);
        tdNewTable.create();
        if (bCopyIndexes) {
            tdNewTable.copyIndexes(strOldTable, strNewTable);
        }
    }
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Source :-&lt;A title="https://support.servicenow.com/kb?id=kb_article_view&amp;amp;sysparm_article=KB0656519" href="https://support.servicenow.com/kb?id=kb_article_view&amp;amp;sysparm_article=KB0656519" target="_blank" rel="noopener"&gt;https://support.servicenow.com/kb?id=kb_article_view&amp;amp;sysparm_article=KB0656519&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Dec 2022 16:11:31 GMT</pubDate>
      <guid>https://www.servicenow.com/community/sysadmin-forum/how-to-clone-a-table/m-p/2409481#M1650</guid>
      <dc:creator>Gunjan Kiratkar</dc:creator>
      <dc:date>2022-12-08T16:11:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to clone a table</title>
      <link>https://www.servicenow.com/community/sysadmin-forum/how-to-clone-a-table/m-p/2410242#M1659</link>
      <description>&lt;P&gt;thank you!&lt;/P&gt;&lt;P&gt;I used the post-New York script from the page you provided and it worked!&lt;/P&gt;&lt;P&gt;When using an extended table, there was a bug that the label of the table became the label of the extended table, but it is minor!&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2022 08:46:51 GMT</pubDate>
      <guid>https://www.servicenow.com/community/sysadmin-forum/how-to-clone-a-table/m-p/2410242#M1659</guid>
      <dc:creator>bonsai</dc:creator>
      <dc:date>2022-12-09T08:46:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to clone a table</title>
      <link>https://www.servicenow.com/community/sysadmin-forum/how-to-clone-a-table/m-p/3011496#M14630</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The table should extend the Task table and once the table is created, there is no way we can change it.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Aug 2024 07:35:44 GMT</pubDate>
      <guid>https://www.servicenow.com/community/sysadmin-forum/how-to-clone-a-table/m-p/3011496#M14630</guid>
      <dc:creator>matrixtushar</dc:creator>
      <dc:date>2024-08-07T07:35:44Z</dc:date>
    </item>
  </channel>
</rss>

