Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to do nested if else #574

Open
ying234 opened this issue Jan 19, 2024 · 3 comments
Open

How to do nested if else #574

ying234 opened this issue Jan 19, 2024 · 3 comments

Comments

@ying234
Copy link

ying234 commented Jan 19, 2024

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"
          }
        ]
      }
    ]
  }
]
@jjrobinson
Copy link

Also hoping this issue can get fixed to make the Rules Engine much power useful.

@abbasc52
Copy link
Contributor

@ying234 complex scenarios can be enabled via actions such as evaluateRule and ExecuteActionWorkflowAsync . Please refer this example - https://microsoft.github.io/RulesEngine/#evaluaterule

@ying234
Copy link
Author

ying234 commented Feb 5, 2024

@abbasc52 looks good for the evaluateRule. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants