How to replicate incident table in a new custom table without Extending it from Incident.

harshchaudh
Tera Contributor
 
6 REPLIES 6

Muhammad Salar
Giga Sage

Hi @harshchaudh You can run this script in background for copying table for testing purpose

cpTable('incident', 'u_incident', true); //Original table incident, new table u_incident

function cpTable(strOldTable, strNewTable, bCopyIndexes) {
    var tu = new TableUtils(strNewTable);
    if (tu.tableExists()) {
        gs.print("Table already exists: " + strNewTable);
        return;
    }

    var gr = new GlideRecord(strOldTable);
    gr.initialize();

    var td = GlideTableDescriptor.get(strOldTable);
    var tdNewTable = new SNC.TableRotationBootstrap(strNewTable, gr.getLabel());

    // Extend if super class found
    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.name + '');
    }

    tdNewTable.setFields(gr);
    tdNewTable.copyAttributes(td);
    tdNewTable.create();

    if (bCopyIndexes) {
        tdNewTable.copyIndexes(strOldTable, strNewTable);
    }

    // Force reload of table schema in memory
    GlideTableManager.invalidateTable(strNewTable);
    GlideCacheManager.invalidateAll();

    gs.print("Table '" + strNewTable + "' copied from '" + strOldTable + "' with fields.");
}

 

Hi @harshchaudh 
Did you try this?