0

I'm having a similar issue with the one described here: How to change item templates and retain existing data

Template_Old 
Title        General Link



Template_New
Title        Single-line text

My problem is that before I change the datasource item template from Template_Old to Template_New, I have to extract the text from General Link field and place it into the Single-Line text. Any piece of ps script would be helpful. Ty

1

Here is the sample code. Not sure how we can use the Set-ItemTemplate and -FieldsToCopy but using the old method we sure can achieve this :

$rootItem = Get-Item -path "Item path"
$targetTemplate = Get-Item "TemplateId or Path here";
# Template_Old_Link is the old field in old template - General Link
# Template_New_Title is the new field in new template - Single Line Text
[Sitecore.Data.Fields.LinkField]$field = $rootItem.Fields["Template_Old_Link"]
$fieldValue = $field.Text
$rootItem.ChangeTemplate($targetTemplate);
$updatedItem = Get-Item $rootItem.ID;
$updatedItem.Template_New_Title = $fieldValue;

Check this and let me know if this script works.

| improve this answer | |

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.