February 17, 2016

How to write Sitecore custom engagement rule condition

Here is sample custom enagement rule

public class CustomEngagementValuePointsCondition<T> : OperatorCondition<T> where T : RuleContext
    {
       
public int Value
        {
           
get
;
           
set
;
        }

       
protected override bool
Execute(T ruleContext)
        {
           
int
value = 0;
           
try

            {
               
if (Tracker.Current.Contact != null)
                {
                    value =
Tracker
.Current.Contact.Value;  
                }

            }
           
catch

            {

            }
           
switch (base.GetOperator())
            {
               
case ConditionOperator
.Equal:
                   
return value == this
.Value;
               
case ConditionOperator
.GreaterThanOrEqual:
                   
return value >= this
.Value;
               
case ConditionOperator
.GreaterThan:
                   
return value > this
.Value;
               
case ConditionOperator
.LessThanOrEqual:
                   
return value <= this
.Value;
               
case ConditionOperator
.LessThan:
                   
return value < this
.Value;
               
case ConditionOperator
.NotEqual:
                   
return value != this
.Value;
               
default
:
                   
return false
;
            }
        }
    }


No comments:

Post a Comment