More in this section
Forums / Module Builder / Change existing field type in module from short to long text

Change existing field type in module from short to long text

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
2 posts, 0 answered
  1. Louis
    Louis avatar
    1 posts
    17 Jul 2015
    17 Jul 2015
    Link to this post
    ​I have a field that initially worked as a short text field but needs to be changed to a long text field to accommodate bigger values.  I have tried changing the character length in the database but it didn't work (see attached file).  Do I need to delete the existing field and re-add it as a long text type?  And ​how do I do that without losing all my data?  Any help would be appreciated.  Thanks.
  2. Velizar Bishurov
    Velizar Bishurov avatar
    143 posts
    18 Sep 2017
    22 Jul 2015
    Link to this post
    Hello Louis,

    You cannot change the type of an existing field, however you can move its value to a newly created LongText field and then delete the old field.

    The way to do this is by first creating a new field of type Long text. After that you can run the following code which will set the data of the long text field to be the same as the data of the short text field.

    var providerName = String.Empty;
    DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
    // Resolve dynamic content item types (plural name in yellow, singular name in red)
    Type magazineType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Magazines.Magazine");
    var allMagazines = dynamicModuleManager.GetDataItems(magazineType).Where(i => i.Status == ContentLifecycleStatus.Master);
    foreach (var item in allMagazines)
        item.SetValue("LongField", item.GetValue("ShortField"));

    In order to use this code the following namespaces must be included:

    using System;
    using System.Linq;
    using Telerik.Sitefinity.DynamicModules;
    using Telerik.Sitefinity.GenericContent.Model;
    using Telerik.Sitefinity.Model;
    using Telerik.Sitefinity.Utilities.TypeConverters;

    The last step is to remove the Short text field from the module.

    Velizar Bishurov
    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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
2 posts, 0 answered