Duration type fields to Dropdown type field type

_bhishek
Tera Guru

I have duration type field available in Business application table .I want to make that field dropdown with specific values like 1day,2 day,3 day etc. I can not directly change type from Duration to Dropdown. I don't want to change column name ,if we will create new field then we would have to create new field with different column name .Also we have data available for existing field ,so we can not directly delete existing field and create new field .

 

My thought is ,We can copy the data for the existing field to new temp field and then we can delete the existing field and create the field with same column name  and again map the data accordingly .

Please confirm if this is fine ,also help me how can i copy data from 1 field to another temporary field .

 

1 ACCEPTED SOLUTION

@_bhishek 

To determine the impact: if that duration field is custom then you will have to find at which all places you have used that, some business rule script, script includes, reporting etc

To copy duration field to string you can run fix script like this

var gr = new GlideRecord("tableName");
gr.addNotNullQuery('durationField');
gr.query();
while (gr.next()) {
    gr.customStringField = gr.durationField.getDisplayValue();
    gr.setWorkflow(false);
    gr.update();
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

6 REPLIES 6

_bhishek
Tera Guru

Thanks Ankur.

_bhishek
Tera Guru

Hello @Ankur Bawiskar 

As i had to change the type for one field from duration to choice .We can not change directly the type from duration to choice .So i created one temporary field and stored existing data in that field .

Then created a new update set.

After that  i deleted the current duration field and added new field with choice type with same column name which i had for duration to avoid other related issues.I was able to do this in lower instance but when i am moving update set ,I am getting error like type conversion is not allowed from duration to choice for this column name.What should i do now . Please help ,do i need to move deletion in separate update set if yes then how should i capture deletion now in lower instance.