Can I change dictionary field type from String to Integer field type?

Cynthia19
Tera Contributor

I can go to dictionary and change the field type from string to integer on a particular field on my incident form. I was wondering if this is an SN recommended approach or should I just delete the field completely and recreate it as an integer

 

Thanks 

 

Please note, there is no data associated to that field 

1 ACCEPTED SOLUTION

Hi Cynthia,

I see you've change your Correct answer to another reply?

I felt I answered your question above and in your specific scenario you had mentioned there was no data involved anyway.

I covered both data and your actual question in my reply. Everything said in the other reply is exactly what I've described above.

My apologies if I missed something?

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

4 REPLIES 4

Allen Andreas
Administrator
Administrator

Hi,

If there was data associated with the field, SN wouldn't let you swap it and so the best practice for that scenario would be to either create a new field, move your data over to that (convert, etc., if applicable) and then delete the "original" and then recreate that and move the data back OR...house the data temporarily somewhere in a current field (like description) and then pull it back out utilizing methods like "setWorkflow(false)" and "autoSysFields(false)" when using GlideRecord to prevent business rules from running and system fields from being updated, respectively.

Long story, but I just wanted to cover that.

In your scenario, since there's no data, then feel free to change the field to type: Integer, this would be fine and shouldn't pose any issue.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi Cynthia,

I see you've change your Correct answer to another reply?

I felt I answered your question above and in your specific scenario you had mentioned there was no data involved anyway.

I covered both data and your actual question in my reply. Everything said in the other reply is exactly what I've described above.

My apologies if I missed something?

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Cynthia,

I tried changing a String field to Integer. ServiceNow displayed the following error if there is a value in the column. To change the column type to Integer, I would have to delete value in all the records for that field whether the value is an integer or not. That is, even if the value is 123, I still had to delete it.

After I deleted all the values, I was able to change the type. So, whether to directly convert the type will depend on whether it is necessary to keep the current value or not. By creating a new field, a script can be used to transfer the values.

find_real_file.png

 

Hitoshi Ozawa
Giga Sage
Giga Sage

Cynthia,

Following script may be used to copy the value from old field to new field.

var grIncident = new GlideRecord("incident");
grIncident.query();
while (grIncident.next()) {
  grIncident.setValue('<new field name>', grIncident.getValue('<old field name>'));
  grIncident.update();
}