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

Ankur Bawiskar
Tera Patron
Tera Patron

@_bhishek 

you should do this carefully as Duration holds value differently and you can store that value in some new string field.

but you will have to identify at which all places this Duration field was used.

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

@Ankur: Thanks for your response .Will there be any impact if we will delete existing Duration type field and create new field with same column name .We are using this field to map values from catalog item submitted to  update data in server form mostly.

Also could you please tell me how can i copy duration field data to string field ?

@_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

@_bhishek 

Hope you are doing good.

Did my reply answer your question?

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