- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2017 04:53 AM
Hi Folks,
We have made a field as string by mistake. Now we need to change it to integer. We have stored only integer value in the field also but in string format.
Is there any way to convert the data type as integer.
Thanks in advance.
Vikash
Solved! Go to Solution.
- Labels:
-
Best Practices
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2017 05:02 AM
HI Vikey,
Fix script sample:
var gr = new GlideRecord("TABLENAME");
gr.addNotNullQuery('INTEGERFIELDNAME');
while(gr.next()){
gr.STRINGFIELDNAME = gr.INTEGERFIELDNAME.toString();
gr.update();
}
post me your feedback
Please Hit ✅Correct, â�ï¸�Helpful, or â�£ï¸�Like depending on the impact of the response
Have a lovely day ahead
Regards,
Divya Mishra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2017 04:58 AM
Hi Vikey,
Only possible way would be:
1. Create a string field.
2. write a fix script to copy the existing values from integer field to string field.
3. Do not forget to do .toString() to the values in integer.
4. Delete the integer field.
post me your feedback
Please Hit ✅Correct, â�ï¸�Helpful, or â�£ï¸�Like depending on the impact of the response
Have a lovely day ahead
Regards,
Divya Mishra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2017 05:02 AM
HI Vikey,
Fix script sample:
var gr = new GlideRecord("TABLENAME");
gr.addNotNullQuery('INTEGERFIELDNAME');
while(gr.next()){
gr.STRINGFIELDNAME = gr.INTEGERFIELDNAME.toString();
gr.update();
}
post me your feedback
Please Hit ✅Correct, â�ï¸�Helpful, or â�£ï¸�Like depending on the impact of the response
Have a lovely day ahead
Regards,
Divya Mishra

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2017 06:14 AM
Hi Vikey,
Didn't you say you were converting a string field to an integer? The answer you marked correct is converting an integer to a string. If it's the other way around, then this is the solution:
var gr = new GlideRecord("TABLENAME");
gr.addNotNullQuery('STRINGFIELDNAME');
while(gr.next()){
var intValue = parseInt(gr.getValue('STRINGFIELDNAME'), 10);
gr.setValue('INTEGERFIELDNAME', intValue);
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2017 10:36 PM
Hey Chuck,
I have mentioned my code as a "sample code" which Vikey can modify and proceed. Cheers
Regards,
Divya

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2017 07:32 AM
The challenge I have found in the community is that most people just copy/paste the script you include and expect to work unless you either put in the specifics, "This is sample untested code" or "Please replace with proper field and table names for your use case", etc. Even then it sometimes fails.
The more specific to their solution, the better. That being said, you don't always know and have to provide specific instructions. In this case his original request to convert a string to an integer
We have made a field as string by mistake. Now we need to change it to integer.
I thought it worth noting that your script did the reverse. In either case, I'm glad he got it resolved.