In the previous post, I talked about the general anatomy of Sitecore Business Rules. In this post, we will dig more into the rule itself and how you can set one up.
In the example of the query string condition, the only things that are required are "Property to set", in this case, they are setting a property called "value". Then they are setting the display text to value.
The first word of a condition text can always be changed to be positive "where" or a negative condition "except where". You can remove the word "where" and it will become "the query string.." or "except the query string", so this positive or negative toggling capability is added automatically.
Now let's break down the code and the "special" syntax.
In the previous post, I mentioned the "special syntax" a rule has in the "text" field. Let's dig more into what this is. This is broken into 4 parameters, not all of which are required.
- Property to set, defines the public property of the class where we want to assign the value coming from the content author input
- Operator or Macro, the operator we want to use to evaluate the condition. In this case, this will be a string comparison operation
- Additional Parameters, this parameter will depend on the type of macro that we use, this could be a default text value if we are using the default macro, it could be a default start path if we’re using the Tree macro (root=/sitecore/content/myitem) – think of it like setting a field source when we’re building a template in Sitecore. A full list of macros can be found in /Sitecore/system/Settings/Rules/Definitions/Macros. This field is seen by Macros and Operators as a URL so it is a name-value list that must have special characters encoded. Example: validation=%5E%5Cd%2B(%5C.%5Cd%2B)%3F%24&validationText=Please enter a valid decimal value&maxLength=2
- Display text, the last parameter is the text representation that we want to show to the content author, this value is clickable and when clicked Sitecore will display the appropriate input control based on the macro that we set on the second parameter
In the example of the query string condition, the only things that are required are "Property to set", in this case, they are setting a property called "value". Then they are setting the display text to value.
The first word of a condition text can always be changed to be positive "where" or a negative condition "except where". You can remove the word "where" and it will become "the query string.." or "except the query string", so this positive or negative toggling capability is added automatically.
Now let's break down the code and the "special" syntax.
Here we can see how this all comes together. In the top left, we have the syntax of the rule. In the middle is how that syntax is displayed to the author. On the top right is what the author configures the rule as. Below those is the code that is executed. Here you can see that the first parameter (the property to set) calls out the public "Value" property on the class. This is the field that the last parameter (value) should be assigned to. So in this case "My Test" will be assigned to the property "Value". Now when the rule executes it has access to the value the content author set and executes logic against that value.
Comments