+1-888-365-2779
Try Now
More in this section

Forums / Bugs & Issues / Module Builder - Unable to change field type

Module Builder - Unable to change field type

8 posts, 1 answered
  1. David
    David avatar
    99 posts
    Registered:
    06 Sep 2012
    09 Mar 2012
    Link to this post
    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.
  2. Stoimen Stoimenov
    Stoimen Stoimenov avatar
    60 posts
    Registered:
    11 Jul 2016
    12 Mar 2012
    Link to this post
    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
    Answered
  3. David
    David avatar
    99 posts
    Registered:
    06 Sep 2012
    13 Mar 2012
    Link to this post
    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.
  4. Rico
    Rico avatar
    88 posts
    Registered:
    30 Aug 2012
    02 Jul 2013 in reply to David
    Link to this post
    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...
  5. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    Registered:
    30 Nov 2016
    05 Jul 2013
    Link to this post
    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
  6. Ryan
    Ryan avatar
    5 posts
    Registered:
    11 May 2013
    11 Jul 2013 in reply to Stanislav Velikov
    Link to this post
    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
  7. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    11 Jul 2013 in reply to Ryan
    Link to this post
    @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.
  8. Ryan
    Ryan avatar
    5 posts
    Registered:
    11 May 2013
    11 Jul 2013 in reply to Steve
    Link to this post
    Interesting....How does that work? Where else is it storing what Custom Field Selector I initially specified?
8 posts, 1 answered