How to delete custom column using fix script?

kevinharalson
Mega Expert

Is there a way to script a column's deletion so that everything is performed as though the column was deleted using the GUI?

The London release has introduced a "Parent Contract" field to the ast_contract which has resulted in our custom "Parent Contract" field added in early 2017 to be redundant. I am working on a fix script to copy the data from the custom field into the OOB field, and would like to be able to delete the custom column as the final step in the script.

 

9 REPLIES 9

This change is to be migrated via an update set across multiple instances, and I desire to implement the change as a 2 step process; commit the update set and run the fix script. Including the deletion into a script will allow for implementation of tested, repeatable results limiting the potential for user error during an extra manual step to be performed following execution of a script.

The following tasks are intended to be performed by the fix script.

1) Copy the data from the custom field into the new OOB field.

2) Adjust report definitions referencing the custom field to use the new OOB field.

3) Drop the custom field from the database

 

Please use below script to delete column

 

var col = new GlideRecord('sys_dictionary');

col.addEncodedQuery('name=abc');// update your query

col.query();

while(col.next()){

 

col.deleteRecord();

 

}

Regards,

Sachin

Will that perform a cascade delete to related indices, form/list layouts, labels, etc for the field being deleted?

Yes, it will do cascade delete for objects you mentioned.

Regards,

Sachin

I have just tested deleting the column from sys_dictionary by deleting the record using the script, but it did not cascade delete records from sys_ui_element or sys_security_acl tables as expected.

 

If it matters, I am needing this functionality in the London release.