- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 10:15 PM
Hi Friends, We have one custom table where we have string fields that we would like to convert into Integer fields.
Please suggest , if this is possible. Because we are not getting the option to select type as integer or decimal for existing columns.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 10:33 PM
Hi @_Samay
We cannot change the datatype if there are any records with value for that field.
If this field is not yet moved to prod instance then you can clear out the data first and then you will be able change the type.
If the field is already in prod then It's better you create a new field, write a script to map the old field data to new field, update all the references of old field to new field and deactivate old field.
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 10:28 PM - edited 10-04-2023 10:30 PM
Hi @_Samay
If you are using script then you can use :
var string ="123";
var intV=parseInt(string,10);
OR
If you want user to put only numbers in string field then use regular expression on that field (client script)
var fieldValue = g_form.getValue('your_field_name');
var regex = /^[0-9]+$/;
// Check regular expression matches
if (!regex.test(fieldValue)) {
alert('Please enter only numbers.');
g_form.setValue('your_field_name', ''); // Clear the field
}
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 10:33 PM
Hi @_Samay
We cannot change the datatype if there are any records with value for that field.
If this field is not yet moved to prod instance then you can clear out the data first and then you will be able change the type.
If the field is already in prod then It's better you create a new field, write a script to map the old field data to new field, update all the references of old field to new field and deactivate old field.
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2023 07:17 AM
Thanks Voona for your reply.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 11:27 PM
short answer is NO
Long answer:
According to ServiceNow, if there's data in a table field, you can't change its data type directly.
To work around this:
You can perform form-level validation to accept only integer values and in the backend, you can use the "parseInt" function to convert it to an integer.
If you absolutely need it as a string, disable the old field and create a new one, but keep in mind you'll lose the existing data.
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.