2

I have a base template with property 'Intro Text' of type multiline text. This base template is used by 4 different templates. Now, one of these templates needs this field as a RTE field. But I can't change the field-type in the base template, because that would break the other components. So I am thinking to create a new field 'Intro Text New' in the template that needs the RTE and I would need to copy all the existing content from the field 'Intro Text' and remove the base template from this template afterwards. Is there a way to migrate field values from one field to another in Sitecore? Also, would there be a better/faster way to solve the problem above?

5

Creating a new field on the template that needs the RTE should work. In order to automate you could use Sitecore Powershell Extensions, something like the following should work (I've not had chance to test this yet):

$rootItem = Get-Item master:/content;
$sourceTemplate = Get-Item "Source-Template-Path-Or-Guid-Here";

Get-ChildItem $rootItem.FullPath -Recurse | Where-Object { $_.TemplateName -eq $sourceTemplate.Name } | ForEach-Object {  
        $_.Editing.BeginEdit()
        $fieldValue = $_.Fields["Intro Text"].Value
        $_.Fields["Intro Text New"].Value = $fieldValue;
        $_.Editing.EndEdit()
}

Corey wrote a useful blog post: https://blogs.perficient.com/sitecore/2016/06/13/sitecore-powershell-change-item-template-and-retain-field-value/ on copying from one template to another and updating fields which I've based this on. Another useful reference here too: https://therelentlessfrontend.com/2017/11/14/sitecore-powershell-to-update-item-fields/

Also I believe Sitecore Rocks allows you to do this using an update query:

update set @#Intro Text New# = '' + @#Intro Text# from /sitecore/content//*[@@templatename = 'Promo'];

One thing to consider though is that if on the template you add the 'Intro Text New' field to you leave the base-template in place you will end up with two fields which may be confusing for content editors so perhaps look at re-organising the base template this is using afterwards etc.

  • Thanks for your answer! I decided to go with writing a (generic) script in c# though, because of the familiarity and ease. The performer class accepts as input a templateid, a rootitemid, a source field name and a destination field name. Would expect this kind of functionality in the sitecore admin out-of-the-box.. – staccata Jul 25 '18 at 11:13
  • No worries, that’s was the other option. I think this is exactly what Sitecore Powershell Extensions was invented for though as it would be impossible for Sitecore to provide for all these kind of use-cases in the admin area. If recommend installing and learning it if you can as saves compiling code and is very re-usable. – Adam Seabridge Jul 25 '18 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.