How to change data type of a field?

vikey1234
Kilo Contributor

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

1 ACCEPTED SOLUTION

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


View solution in original post

19 REPLIES 19

I know of no such list. If you feel one would be valuable, consider putting in an enhancement request.




Enhancement requests: Tell us how you would improve the ServiceNow product


Where should I search for the data type compatibility list with each other. Is it documented somewhere? if yes. can you please send me the link.




Regards,


Vikash


I am not sure. I don't have any such list. I just tried changing the data type on my personal dev instance.


Hey Vikey,



I tried my solution and it works.



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


The best way to find it if you can change a data field type is to click the magnifying glass on the type field in the dictionary. It will present a list of valid choices. If your target type doesn't appear, you'll have to do the method of creating a new field with the new type.