Best Practice to change the type of existing field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
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
3 weeks ago
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
3 weeks ago
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
3 weeks ago
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
3 weeks ago
@Ankur Bawiskar - Thank you, I understood that the fields do not exist anywhere except in Dev, So I believe better to delete those and can use the same name to the new field with correct data type? So that I didn't miss the any related client scripts/BR if this field name has been called ?
