6

I have some personalization conditions. None of these seem to execute. When debugging, none of the rules stop with break points. I have tried using the most simple built in rules such as when [date] has passed to no avail. It is just not stepping through the conditions.

This is on Sitecore.NET 8.2 (rev. 160729)

I have values Xdb.Enabled and Xdb.Tracking.Enabled set to true.

I am testing in normal mode. I have Sitecore.xDB.base license.

I see nothing in logs.

Below are the control properties and personalization rules. If the control does not have a data source nothing shows.

Control Properties

Personalization Rules

I have seen all of the custom rules execute correctly. This is the only rule that I have not seen execute correctly. Possibly if there is one rule that is incorrect it would stop personalization running altogether?

public class AptifyMemberDuesPaidThruCondition<T> : OperatorCondition<T> where T : RuleContext
{
    private readonly IAptifyAuthenticator _aptifyAuthenticator;

    public AptifyMemberDuesPaidThruCondition() : this(ServiceLocator.ServiceProvider.GetService<IAptifyAuthenticator>())
    { }

    public AptifyMemberDuesPaidThruCondition(IAptifyAuthenticator aptifyAuthenticator)
    {
        _aptifyAuthenticator = aptifyAuthenticator;
    }

    public string DuesPaidThru { get; set; }

    /// <summary>
    /// This function will be called to test the condition
    /// </summary>       
    protected override bool Execute(T ruleContext)
    {

        //Check if the user is logged in, otherwise return false
        if (!_aptifyAuthenticator.UserAptifyAuthenticated())
            return false;

        DateTime dateTime = DateUtil.ParseDateTime(this.DuesPaidThru, DateTime.MinValue);
        if (dateTime.Kind != DateTimeKind.Utc)
        {
            string str = string.Concat("AptifyMemberDuesPaidThruCondition<T> expects UTC date, but date with different kind has been assigned to Now property: ", this.DuesPaidThru);
            Log.Warn(str, this);
        }

        var actualDuesPaidThru = _aptifyAuthenticator.GetUserCustomerPropertyDate(AuthenticatedPropertyName.DuesPaidThru);

        if (!actualDuesPaidThru.HasValue)
            return false;

        return DateComparer(actualDuesPaidThru.Value, dateTime, GetOperator());

    }

    private bool DateComparer(DateTime date1, DateTime date2, ConditionOperator conditionOperator)
    {

        switch (conditionOperator)
        {
            case ConditionOperator.Equal:
                return date1.Equals(date2);
            case ConditionOperator.LessThan:
                return date1 < date2;
            case ConditionOperator.LessThanOrEqual:
                return date1 <= date2;
            case ConditionOperator.GreaterThan:
                return date1 > date2;
            case ConditionOperator.GreaterThanOrEqual:
                return date1 >= date2;
            case ConditionOperator.NotEqual:
                return !date1.Equals(date2);
            default:
                return false;
        }

    }
}

Any ideas where to troubleshoot?

Update: this started working after I went to web database, modified a property (not related to personalization) and saved the item. This indicates some other kind of issue.

Update 2: it stopped working with no changes. I can change the item and see changes, but personalization is now not working. It is like it just turns off.

10
  • Do you test in normal mode? Rules are not executed in edit or preview
    – Marek Musielak
    Commented Oct 11, 2018 at 17:24
  • I am testing in normal mode. Commented Oct 11, 2018 at 17:31
  • Can you add some screenshots of your rule configurations and some code snippets of your config and/or any custom rule actions you've defined? Commented Oct 15, 2018 at 13:02
  • Added screenshots. Shows built-in rule not working. Commented Oct 15, 2018 at 15:12
  • Is the component which holds the rules cached? Commented Oct 15, 2018 at 19:32

4 Answers 4

3

I faced a similar issue on my instance. The code was returning true/false correctly but the rendering was not updated in Sitecore.

Interesting, the rules started working when I disabled the tracking of personalization enter image description here

2
  • Strange but, it worked! Commented Sep 22, 2020 at 20:50
  • I do not believe this option is available in Sitecore 9.0.2 so I am trying to figure out what I would do instead... Commented Mar 5, 2021 at 16:05
0

The sitecore default rules are supposed to be executed without additional steps. You can check the following to troubleshoot further. 1. Is the personalization rendering added to shared renderings section or final rendering section? 2. Did you publish the page and if so check the web database to see if the personalization rendering is present in web database.

1
  • Personalization rendering is in final rendering section. Personalization is in web database. Commented Oct 15, 2018 at 13:51
0

Sitecore default Rules execute without any custom code but if you want to write your own Rules then you can use below:

public class AptifyMemberDuesPaidThruCondition : WhenCondition where T : RuleContext

However there can be many reasons for this issue. Refer:

Is it possible to use any personalisation rules without xDB

0

I also faced this issue and I figured out that it worked when I changed from Experience Editor to Preview mode.

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.