1

I am using Sitecore 10 update 1, I am saving the birth date of the contact in Xprofile. The data saved in the database is UTC time, for example, if the birth date is 12 April 2021 the saved value in the database will be 11 April 2021 as the timezone is UTC + 2:00.

The Server time in the configuration is <setting name="ServerTimeZone" value=""/>

Is there a configuration that converts the DateTime to server time before the rule executes?

1
  • I recommend leaving like that and just convert it from UTC to local time on your own custom code. Apr 12 '21 at 15:47
1

In the below-metioned steps, In Step 5 PersonaliseRuleService you can write your server-side code before the rule executes. To start with custom personalization, perform the below steps:

Step 1: Go to the path /sitecore/system/Settings/Rules/Definitions/Tags right-click on Tags and add new customize Tag (I have given name CustomPersonalization):

enter image description here

Step 2: Go to the path /sitecore/system/Settings/Rules/Conditional Renderings and expand conditional rendering and add created tag into the Tags property of default tag as below:

enter image description here

Step 3: Go to the path /sitecore/system/Settings/Rules/Definitions/Elements

  • Right-click on Elements and add new Element folder (I have given the name CustomPersonalization).

  • Right-click on CustomPersonalization and add new condition and set the Text and Type property of condition.

    Text Property: Give the condition with Rule which will show to the content editor.

    Type Property: Specify our class name with a namespace followed by the assembly name, where we will write our personalization rule business logic.

enter image description here

Step 4: Now you need to add created tag into default tag, Tags property of element folder:

enter image description here

Step 5: Write your personalization rule business logic as below or update your code as per requirement:

public class PersonaliseRuleService<T> : StringOperatorCondition<T> where T : RuleContext
    {
        public string Value { get; set; }
        protected override bool Execute(T ruleContext)
        {
            Assert.ArgumentNotNull(ruleContext, "ruleContext");
            HttpCookie customCookie = HttpContext.Current.Request.Cookies["Custom_Personalization"];      
        if (Value.ToLower().Equals(customCookie.Value.ToLower()))
            {
                return true;
            }
            return false;
        }
    }

Step 6: After completion of all the above changes, you need to set your personalization rule on the component using experience editor. Go to the page presentation details and select that rendering and click on personalize section. Add your personalization rule and select Edit rule then select our created rule and update the data source from the content property.

enter image description here

enter image description here

enter image description here

Same you can create a more custom rule to show relevant content to the visitor.

For more details, see Blog Post: Custom Personalization Rules in Sitecore 9

0

As mentioned in Comment You can create custom code for conversion or else you can create your own custom rule for Personalization based on date, For implementing the custom rule please follow the blog .and In step 2 you can add the condition like where the contact Birthdate is [DOB,Integer,,DOB]

In code file do the following things

Get the DOB from xdb and custom rule then convert it to Date time format. after converting both the things, Compare both DOB values. based on the comparison result ,you can show the content to the user.

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.