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 would take it as a good advice from a great person ctomasi


Chuck Tomasi
Tera Patron

In some cases, you can change a string field to another type (e.g. HTML, or Journal), but you cannot change it when the underlying data type is different (e.g. String to Integer.)



As others have suggested, create a new integer field, copy the contents, and deactivate (or delete) the old field.


If I change string to HTML or journal, does that also wipe out existing data?

Kalaiarasan Pus
Giga Sage

I feel the data type change will be allowed if the data types are compatible.


I would advise you to try this on a demo instance first.



Edit: Checked on my dev instance(Helsinki) and changing string to int is not possible.


In demo instance I tried by changing string field to integer but its readonly after saving.



Do any one know or have the list of data types that are compatible with each other?