--- alias: tutorials-sort-rule-sets-custom-sort-rules search: boost: 2 description: "Create custom sort rules with DEE logic and connect them to sort rule sets when the standard rules are not enough." --- # Custom Sort Rules For unique business requirements not covered by pre-defined rules, create custom Sort Rules and then add them to a Sort Rule Set. ## Create the DEE Rule Create a **Dynamic Execution Engine (DEE)** rule that implements the custom sorting logic required by the business scenario. ![Screenshot showing a DEE action used to implement custom sort rule logic.](images/sort-rule-set-custom-dee-rule.png) ## Create the Rule Create a [[user-guide-create-rule|Rule]] with one of the following scopes and assign the **DEE** to it: - `SortRuleSetMaterial` - `SortRuleSetResource` ![Screenshot showing a rule configured with a sort rule set scope.](images/sort-rule-set-custom-rule-scope.png) ### Example DEE Rule ```csharp UseReference("", "Cmf.Foundation.Common"); UseReference("", "Cmf.Foundation.Common.Exceptions"); UseReference("Cmf.Foundation.BusinessObjects.dll", "Cmf.Foundation.BusinessObjects"); UseReference("Cmf.Navigo.BusinessObjects.dll", "Cmf.Navigo.BusinessObjects"); UseReference("Cmf.Foundation.BusinessOrchestration.dll", ""); string attributeName = "MySortingAttribute"; if (!Input.ContainsKey("Material") || !(Input["Material"] is IMaterial)) { throw new ArgumentNullException("Material"); } Dictionary output = new Dictionary(); IMaterial material = (IMaterial)Input["Material"]; material.LoadAttributes(new System.Collections.ObjectModel.Collection() { attributeName }); if (material.Attributes.ContainsKey(attributeName)) { output["Result"] = material.Attributes[attributeName]; } else { output["Result"] = string.Empty; } return output; ``` For more information, see our Developer Portal page for Custom Sort Rules in . ## Create the Sort Rule Entity Create the **Sort Rule** entity that references the rule created in the previous step, and then add that Sort Rule to the target **Sort Rule Set** through [[user-guide-manage-rules]]. ![Screenshot showing the sort rule entity referencing the custom rule.](images/sort-rule-set-custom-sort-rule-entity.png) !!! note Custom rules require development expertise and should be thoroughly tested before being used in production dispatching scenarios.