Personalization rules do not work after upgrading to Sitecore XP 9.2.0 and later


Description

Personalization rules might not work after upgrading to Sitecore XP 9.2.0 and later because the previous conditions have been removed and replaced by the items with new IDs. The issue affects the rules based on the conditions given in the following table:

Item name and path Old item ID New item ID
Campaign was Triggered;
/sitecore/system/Settings/Rules/Definitions/Elements/Visit/Campaign was Triggered
{D379525C-4DE6-4738-89ED-60CC0B8F91E5} {0290AA90-B948-4C8C-B576-F3C17F9DE389}
Day of Week;
/sitecore/system/Settings/Rules/Definitions/Elements/Date/Day of Week
{1F15625B-8BDC-4FD2-8F0C-6EE2B8EF0389} {C18B0900-ED61-47A8-AEF0-AD6D133512C8}
Device Type;
/sitecore/system/Settings/Rules/Definitions/Elements/Device/Device Type
{659CC5E0-6356-44DD-B562-6C590525121C} {F563E8D0-1D8A-4744-BD90-3C8D7E483884}
Matches Pattern;
/sitecore/system/Settings/Rules/Definitions/Elements/Visitor/Matches Pattern
{E00DB4F0-B206-4544-AD90-25D201CFB62C} {08A70C4F-93B5-409E-9967-3892AAEB3BC2}

Solution

To resolve the issue, consider one of the following options:

// Collect all the affected items (these may be all content items or items of a specific template) and use the method below for each item:

public void UpdateLayoutField(Item item)
{
    bool isSharedLayoutFieldUpdated = false; 
    foreach (var language in item.Languages)
	{
        Item itemInLanguage = _database.GetItem(item.ID, language); 
        if (itemInLanguage.Versions.Count > 0)
		{
            foreach (Item itemVersion in itemInLanguage.Versions.GetVersions())
			{
                foreach (Field f in itemVersion.Fields)
                {
                    if (f.ID == FieldIDs.FinalLayoutField)
                    {
                        itemVersion.Editing.BeginEdit(); 
                        string fieldValue = Sitecore.Data.Fields.LayoutField.GetFieldValue(itemVersion.Fields[FieldIDs.FinalLayoutField]);
						
                        // Add the logic to change the old ID to the new one

                        LayoutField.SetFieldValue(f, fieldValue); 
                        itemVersion.Editing.EndEdit();
                    }
                }
                if (!isSharedLayoutFieldUpdated)
                {
                    foreach (Field f in itemVersion.Fields)
                    {
                        if (f.ID == FieldIDs.LayoutField)
                        {
                            itemVersion.Editing.BeginEdit(); 
                            string fieldValue = LayoutField.GetFieldValue(itemVersion.Fields[FieldIDs.LayoutField]);

                            // Add the logic to change the old ID to the new one
							
                            LayoutField.SetFieldValue(f, fieldValue); 
                            itemVersion.Editing.EndEdit(); isSharedLayoutFieldUpdated = true;
                        }
                    }
                }
			}
		}
	}
}