Best Practice to change the type of existing field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tuesday - last edited Tuesday
I would like to change the existing fields type from String to Checkbox and From Integer to Currency,
What is the best way to do this.
Inactivating the Existing fields and creating a new one with the same name is not working as the error is coming up and showing the field with same name exists.
Assist on the best ServiceNow practice approach.
TIA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tuesday
if these fields are not in production, better to Delete them and re-create with Proper field type
Some field types change is not allowed
If already in production then deactivate older field and create new and store data in new field by running fix script
Simplifying Field Changes in ServiceNow: Tips and Limits
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tuesday
Hi @Ankur Bawiskar
Yes, Field is already in production. Can you let me know how to store data in new field by running fix script. If there are 5 fields which requires the data type change, then does all the fields requires a script needs to be run in production as well?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
yes all will require update.
you will get of scripts from community etc to handle this
something like this will help you to get started
var grRecords = new GlideRecord('YOUR_TABLE_NAME');
grRecords.addNotNullQuery('old_field_name'); // Only query records that have a value in the old field
grRecords.query();
gs.info('Starting data migration for table: YOUR_TABLE_NAME. Records found: ' + grRecords.getRowCount());
while (grRecords.next()) {
// Get the value from the old field
var oldValue = grRecords.getValue('old_field_name');
// Set the value of the new field
// Note: The type conversion is handled implicitly by GlideRecord based on the new field's dictionary definition
grRecords.setValue('u_new_field_name', oldValue);
// Optional: Add a comment or log for debugging (remove for production run)
// gs.info('Updating record ' + grRecords.getDisplayValue() + ': copied value ' + oldValue);
// Prevent business rules and system fields from updating
grRecords.setWorkflow(false);
grRecords.autoSysFields(false);
// Update the record
grRecords.update();
}
I believe I answered your question
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tuesday - last edited Tuesday
Hi @Yathvika ,
Even if you are able to change an existing field type from String to Checkbox, it is not a recommended practice as it can cause hidden issues such as data loss and need to thread carefully
The safer approach is to create a new field with the correct data type
If you are receiving an error while creating the new field, it is likely because the system is trying to reuse the same column name. You can keep the same label for the new field, but slightly tweak the backend (column) name to avoid conflicts
Thanks and Regards,
Mohammed Zakir
