0

I have a template and it is inherited. I have a field called website. I need to change the website field from internal link to a general link. When i do that, I loose all the values. How can i retain the values when i change the field from internal link to general link. I thought about this by adding another field(WebsiteTwo) in the template and copying all the values from the Website field to the WebsiteTwo field and then changing the Website field to general link and copy the values from websitetwo to website. I don't know if it is a good way of doing this. Is there a better way?

1 Answer 1

1

Internal link and General link are two different field types in Sitecore, where the Internal link is the system type field (We generally try to avoid the use of it) and the General link is a link type field. Both field stores value in different ways in Sitecore. You can see it by switching the view into raw values. Internal link stores the item path of Sitecore item -

/sitecore/content/Home

and General link stores value in link tag as below -

<link text="" anchor="" linktype="internal" class="" title=""  querystring="" id="{F7A54FFC-68E5-5474-8CB1-D30A6206227F}" />

There may be multiple ways to not losing values after field changes here but I would suggest you, write a script or c# code to update the value of your internal link similar to the general link field, and once all the field will have general link type of value in internal link you can change the field type. You will not lose value in this way.

For example- If your internal link has value like /sitecore/content/Home/test1. Your code will first get the ID of the given path item (here test1 item) using its path value in the field. Then add the ID value in the below string and update the value -

<link text="" anchor="" linktype="internal" class="" title=""  querystring="" id="Internal Link Path Item's ID" />

Although this is the wrong format in the Internal link but the correct format for the General link field.

It is always recommended to take a backup of the databases during these types of updates.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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