0
votes

I want to transfer content of items that belong to one template into another template.

For example, I have 5 fields in first template:

  • Tags
  • Image
  • Download link
  • Title
  • Date

and 5 fields in another template:

  • Type
  • Picture
  • Download Text
  • Title
  • Date

Here first two fields are different in the both the templates and remaining 3 fields are same.

So I want to migrate content of items that belong to first template to the second template. Also, I would like to highlight second template is a newly created template and currently no item from that template is created. So ultimately I am modifying the template of 100 items.

I tried overriding change template method of sitecore TemplateManager.ChangeTemplate(Item item, TemplateChangeList changes) but it empties the fields rather I want to retain the field data.

If anyone has any idea about this, please help.

2
After this operation, would you still need your original template? Or would it be ok if it gets destroyed in the process? - Mark Cassidy
Ideally original template should not be impacted - Natasha Batra

2 Answers

1
votes

I don't think there wouldn't be much difficulty to migrate all contents by changing the template. But, the main issue is that there are a number of page items which have to be changed to another template.

If you do, you can use PowerShellExtension. It takes only 1 second.

You can get the script idea from Sitecore Workflow Is Not Working

0
votes

A solution is to inhertitance this fields, (using the "Base template" Field).

A other solution is to create your own change template command. You can found here sample code: http://sitecore.stockpick.nl/nederlands/dialoge-box-in-een-command/ (it is a dutch article)

In code use: item.ChangeTemplate(template); and fill in the new field with the already stored values from the old template.