Can changing the type from Duration to Integer in dictionary will Capture only days for a field?

SAS21
Tera Guru

Hi 

 

Have a Requirement that need to capture only the days for a duration field. 

Business doesn't want to delete the existing field which is of type Duration and It has the data for 7k records.

So can clearing the field through fix script and changing the type of the field to Integer will fix ?

 

after clearing the field how to populate the Integer value for the historical records? 

 

 

 

2 REPLIES 2

Anil Lande
Kilo Patron

Hi,

It is not recommended to change the type of any dictionary. Also you will not be able to change its type from Duration to Integer.

In such cased we should always create a new field and start using new field. Once all configurations are done you can write fix script to copy data of existing field to new custom field (by converting it in the expected format/type).

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Thank you Anil for the explanation. Is the below fix script correct?  is the new field will have only days? 

 

u_days_onhold is the duration field

u_days_onhold1 is the new field created and is of integer type

var gr = new GlideRecord("incident");
gr.addEncodedQuery('u_days_onholdISNOTEMPTY');
gr.query();
while (gr.next()) {
gr.u_days_onhold1=gr.getValue('u_days_onhold');
gr.setWorkflow(false); //Do not run business rules
gr.autoSysFields(false); //Do not update system field
gr.update();
}