Extend a table to another table

Priyanka Patil2
Tera Contributor

I have created a custom table but mistakenly forgot to extend a table.How can we extend a table to another table which is already created? Is is good practice to make such changes?

Thanks...

1 ACCEPTED SOLUTION

AbhishekGardade
Giga Sage

Hello Priya,

IMPORTANT NOTES:

  1. Always test first in a test or development ServiceNow instance
  2. This script does work with tables with data in them, however I suggest only running this on new or empty tables.
  3. This is a manual step and isn't captured in an update set.

STEPS TO EXTEND TABLE: Elevate your privileges to security admin


In scripts - background run this script (replacing variables as needed)

//Replace <source_table> with the table you want to extend
//Replace <table_extension> with the table you want to extend to, like cmdb_ci or task
var table = '<source_table>';
var old_parent = '';
var new_parent = '<table_extension>';

var changer = new GlideTableParentChange(table);
changer.change(old_parent, new_parent);

If this is not much rework for you, I would suggest you to create the table(extend) from the scratch.

Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade

Thank you,
Abhishek Gardade

View solution in original post

3 REPLIES 3

AbhishekGardade
Giga Sage

Hello Priya,

IMPORTANT NOTES:

  1. Always test first in a test or development ServiceNow instance
  2. This script does work with tables with data in them, however I suggest only running this on new or empty tables.
  3. This is a manual step and isn't captured in an update set.

STEPS TO EXTEND TABLE: Elevate your privileges to security admin


In scripts - background run this script (replacing variables as needed)

//Replace <source_table> with the table you want to extend
//Replace <table_extension> with the table you want to extend to, like cmdb_ci or task
var table = '<source_table>';
var old_parent = '';
var new_parent = '<table_extension>';

var changer = new GlideTableParentChange(table);
changer.change(old_parent, new_parent);

If this is not much rework for you, I would suggest you to create the table(extend) from the scratch.

Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade

Thank you,
Abhishek Gardade

sachin_namjoshi
Kilo Patron
Kilo Patron

you should delete existing custom table and create new table with extended table.

Take backup of data from existing custom table before deleting so that you can import it back in new table.

 

Regards,

Sachin

wertyuiol
Tera Contributor

I'm not being able to use the script to change the parent table. I created a new table and extended in this case from "Task".

This is what ServiceNow displays whenever you try to change the parent table from the UI.

wertyuiol_0-1672327095959.png