Module Builder - Unable to change field type

Posted by Community Admin on 04-Aug-2018 15:45

Module Builder - Unable to change field type

All Replies

Posted by Community Admin on 09-Mar-2012 00:00

I added a custom Field of type Choices. I now want it to be of Short text type. I deleted the field and added it back as a Short text type. After I clicked the button "Update widget templates and finish" the type reverted back to Choices.

Posted by Community Admin on 12-Mar-2012 00:00

Hi David,

Recreating a field with the same name but different type is not as simple as it looks because it requires some heavy database manipulations. What I am suggesting is delete the choices field and save. Then open again the fields editor, add a field with same name and short text type and save. Avoid deleting and adding a field in the same phase, consider saving between these actions. This should work but in case you encounter some problems we have a knowledge base article that should help.

Feel free contacting us if you still have any problems.

Greetings,
Stoimen Stoimenov
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 13-Mar-2012 00:00

I did what you said and it worked. As you said the key is to delete the field and save it before re-adding it.

Posted by Community Admin on 02-Jul-2013 00:00

And what happens if you already have data defined in this column that you want to retain? I don't believe you can simply delete the column, and then re-add it (as the underlying data would also be deleted)...

For example, what happens if I had a custom field (of type short text), and originally associated with a 'custom' field (with a defined Virtual Path). However, suppose I now want to change the underlying virtual path to point to somewhere different)

Example: original virtual path was = 'SitefinityWebApp.Custom.Controls.MyFieldSelectorNamespace.MyFieldSelector' and now I want it to be 'SitefinityWebApp.Custom.Controls.MyNewFieldSelectorNamespace.MyFieldSelector'

Reasons to do this? Say in the original virtual path, I was using a standard asp.net DropDownList to render the values, and in the new virtual path, I was the telerik RadComboBox instead ... so basically the underlying code/purpose of the field is the same, just that it uses a different control to render the info...

Hope this makes sense. What would be the approach to take to change this around? Again, I want to keep the underlying data stored in the original field...

Posted by Community Admin on 05-Jul-2013 00:00

Hi,

Recreating the field as described in the KB article will be needed. To save the data tough export the data stored in the field that have to be changed or save the data in another field trough the API.

DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
           Type iedcnewsType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Test.Test");
 
           var liveItems = dynamicModuleManager.GetDataItems(iedcnewsType);
 
           foreach (var item in liveItems)
           
               var fieldToBeDeletedValue = item.GetValue("FieldToBeDeleted");
               //export to suitable format
               //...
               //copy this field data in another field, or a field created just for this purpose
               item.SetValue("TemporaryStorageField", fieldToBeDeletedValue);
               dynamicModuleManager.SaveChanges();
           
Also instead of exporting the data create new module with the module builder and create items for this module that will hold the field values (those items can have the same titles as the items in your module for easier import back to the original module).

Regards,
Stanislav Velikov
Telerik
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 11-Jul-2013 00:00

What about changing the type in the Administrators settings section? Is this going to cause problems down the road?

For reference I am talking about: Settings->Advanced->DynamicModules->Controls->"Your Model Dynamic Module" -> Views -> CategoryBackendEditView->Sections->MainSection->Fields->"Your field name"->FieldType

Posted by Community Admin on 11-Jul-2013 00:00

@Ryan
  Sounds good, and will work...however any change to the module...ANY CHANGE in the UI will wipe out what you just did....like gets re-generated.

Posted by Community Admin on 11-Jul-2013 00:00

Interesting....How does that work? Where else is it storing what Custom Field Selector I initially specified?

This thread is closed