Mala Mohan
Mala Mohan

Reputation: 91

How to change Sitecore Template field Item Id without data loss?

I recently noticed there is a difference in Item Id for a Sitecore template field between 2 environments (Source and Target). Due to this, any data changes to the field value for the dataitem using the template is not reflecting to target Sitecore database.

Hence, we manually copy the value from source to target and which takes lot of time to sync the 2 environments. Any idea how to change the template field Item Id in Sitecore without data loss in target instance?

Thanks

Upvotes: 2

Views: 1685

Answers (3)

jammykam
jammykam

Reputation: 16990

The template fields have most likely been created manually on the different servers, as @AdrianIorgu has suggested. I am going to suggest that you don't worry about merging fields and tools.

What you really care about is the content on the PRODUCTION instance of your site (assuming that this is Target). In any other environment, content should be regarded throwaway.

With that in mind, create a package of the template from your PRODUCTION instance and the install that in the other environments, deleting the duplicate field from the Source instance. The GUIDs of the field should now match across all environments. Check this into your source control (using TDS or Unicorn or whatever). You can then correctly update any standard values and that will be reflect through the server when you deploy again.

If your other environments (dev/qa/pre-prod) result in data loss for that field then don't worry about it, restore a backup from PROD.

Upvotes: 3

Adrian Iorgu
Adrian Iorgu

Reputation: 611

Most likely that happened because the field or the template was added manually on the second environment, without migrating the items using packages, serialization or a third-party tool like TDS or Unicorn.

As @SitecoreClimber mentioned above, you can use Razl to sync the two environments and see the differences, but I don't think you will be able to change the field's GUID, to have the two environments consistent, without any data loss. Depending on the volume of your data, fixing this can be tricky.

What I would do:

  1. make sure the target instance has the right template by installing a package with the correct template from source (with a MERGE-MERGE operation), which will end up having a duplicate field name
  2. write a SQL query to get a list of all the items that have value for that field and update the value to the new field

Warning: this SQL query below is just a sample to get you started, make sure you extend and test this properly before running on a CD instance

    use YOUR_DATABASE
    begin tran

    Declare @oldFieldId nvarchar(100),  @newFieldId nvarchar(100), @previousValue nvarchar(100),  @newValue nvarchar(100)

    set @oldFieldID = '75577384-3C97-45DA-A847-81B00500E250' //old field ID 
    set @newFieldID = 'A2F96461-DE33-4CC6-B758-D5183676509B' //new field ID 

    /* versionedFields */
    Select itemId, fieldid, value
    from [dbo].[versionedFields]      f with (nolock)
    where f.FieldId like @oldFieldID

Upvotes: 1

Vlad Iobagiu
Vlad Iobagiu

Reputation: 4118

For this kind of stuff I sugest you to use Sitecore Razl.

It's a tool for comparing and merging sitecore databases.

Razl allows developers to have a complete side by side comparison between two Sitecore databases; highlighting features that are missing or not up to date. Razl also gives developers the ability to simply move the item from one database to another.

Whether it's finding that one missing template, moving your entire database or just one item, Razl allows you to do it seamlessly and worry free. It's not a free tool, you can check here how you can buy it:

https://www.razl.net/purchase.aspx

Upvotes: 0

Related Questions