Converting Checkbox field to Yes/No Dropdown(choice list)

kartheeknalli
Kilo Contributor

Hi,

Can anyone please suggest, how can we convert field type of Checkbox to Dropdown(choice list) with choices as Yes No?

I want to change existing field type only as new field creation will cause field name change and will impact scripts where this field is used(Have many fields to make same change)

 

Thanks in advance

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

As Ashutosh noted, you need to create a new field or you will have data issues. You may not even be able to convert a True/false to a choice list. The system restricts certain types of data type changes.

 

If you want the field name to be the same, then I recommend the following approach.

  1. Create  a new choice field ex: u_choice1 and populate it with Yes/No values
  2. Use a script to copy your true values to Yes, and false values to no from the old field (u_bool) to the new field (raise your hand if you need help with this part
  3. Delete the old field (u_bool)
  4. Create a new u_bool field of type choice
  5. Use another script to copy field values from u_choice1 to u_bool
  6. Delete u_choice1

Now you have a u_bool field of type choice with the true/false values as yes/no values.

 

View solution in original post

7 REPLIES 7

Hi Chuck

How do I do that:

2. Use a script to copy your true values to Yes, and false values to no from the old field (u_bool) to the new field (raise your hand if you need help with this part

Mary
Mega Guru

Hello-can you provide some guidance with the Script creation--"Use a script to copy your true values to Yes, and false values to no from the old field (u_bool) to the new field" thanks much

There are probably more clever ways to do this, but this seems to work (after you make the necessary changes):

var NAME = 'Fix Script Example: ';

try {
   gs.log(NAME + 'Starting processing');

   var gr = new GlideRecord('some-table');
   gr.addNotNullQuery('from_tf_field');
   gr.query();
   var row_count = gr.getRowCount();
   var count = 1;
   while (gr._next()) {
      if (gr.from_tf_field) {
         gr.u_to_yn_field = 'yes';
      }
      else {
         gr.u_to_yn_field = 'no';
      }
      gr.update();
      if (count % 1000 == 0) {
         gs.log(NAME + 'Updated ' + count + ' records out of ' + row_count);
      }
      ++count;
   }
}
catch (err) {
   gs.error(NAME + err);
}
finally {
   gs.log(NAME + 'End processing');
}