microsoft / microsoft/RulesEngine

How to do nested if else

Open
#574 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
4.4k
Forks
616
Avg merge
6m
Merged PRs (30d)
2

Description

Is there way to do such nested if rules? Is there setting to make the parent rule expression also evaluated even if there are nested child rules?

if(loyaltyFactor > 4)
{
    if(totalOrder > 3)
    {
    ...
    }
   else
    {
    ...
    }
}
else
{
...
}
[
  {
    "WorkflowName": "Discount",
    "Rules": [
      {
        "RuleName": "GiveDiscount30NestedOrExample",
        "SuccessEvent": "30",
        "ErrorMessage": "One or more adjust rules failed.",
        "ErrorType": "Error",
        "Operator": "OrElse",
        "Rules": [
          {
            "RuleName": "ParentRule",
            "ErrorMessage": "One or more adjust rules failed.",
            "ErrorType": "Error",
            "RuleExpressionType": "LambdaExpression",
            "Operator": "OrElse",
            "Expression": "input1.loyaltyFactor > 4",
            "Rules": [
              {
                "RuleName": "SubHighLoyaltyLowNumberOrders",
                "ErrorMessage": "One or more adjust rules failed.",
                "ErrorType": "Error",
                "RuleExpressionType": "LambdaExpression",
                "Expression": "input2.totalOrders <= 3"
              },
              {
                "RuleName": "SubHighLoyaltyHighNumberOfTotalOrders",
                "ErrorMessage": "One or more adjust rules failed.",
                "ErrorType": "Error",
                "RuleExpressionType": "LambdaExpression",
                "Expression": "input2.totalOrders > 3"
              }
            ]
          },
          {
            "RuleName": "LowLayaltyHighNumberOfTotalOrders",
            "ErrorMessage": "One or more adjust rules failed.",
            "ErrorType": "Error",
            "RuleExpressionType": "LambdaExpression",
            "Expression": "input2.totalOrders > 15"
          }
        ]
      }
    ]
  }
]

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the nested Rules JSON and the C# conditional example in the issue; determine whether the parent expression is evaluated alongside child rules and how nested if/else is represented. A complete outcome would be a clear supported configuration or documentation answer, with behavior confirmed for the shown loyaltyFactor and totalOrders cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.