microsoft / microsoft/RulesEngine

Access Rule(s) In Other Rules

Open
#221 7 comments 0 reactions 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

Hello,

I am stuck with one scenario where I need to call multiple rules in 1 rule, here is simple example which I would like to achieve. Any help in solving the scenario or direction will be appreciated.

[
{
"WorkflowName": "PaymentRule",
"Rules": [
{
"RuleName": "MinimumPayment",
"SuccessEvent": "10",
"ErrorMessage": "Error",
"ErrorType": "Error",
"RuleExpressionType": "LambdaExpression",
"Operator": "OrElse",
"Rules": [
{
"RuleName": "IsPaymentEligible",
"ErrorMessage": "Error",
"ErrorType": "Error",
"RuleExpressionType": "LambdaExpression",
"Expression": "input1.PaymentAmount > 0 AND (input1.IsEligible=="true" AND input1.PaymentFrequency==input1.PaymentDuration ) AND input1.PaymentFrequency < input1.PaymentCycle ",
"Actions": {
"OnSuccess": {
"Name": "OutputExpression",
"Context": {
"Expression": "(input1.PaymentAmount)"
}
}
}
},
{
"RuleName": "elsePaymentEligible",
"ErrorMessage": "Error",
"ErrorType": "Error",
"RuleExpressionType": "LambdaExpression",
"Expression": "input1.PaymentAmount > 0 AND input1.IsEligible=="false" ",
"Actions": {
"OnSuccess": {
"Name": "OutputExpression",
"Context": {
"Expression": "input1.PaymentFrequency"
}
}
}
}
]

  },
  {
    "RuleName": "BonusPayment",
    "SuccessEvent": "20",
    "ErrorMessage": "Error",
    "ErrorType": "Error",
    "RuleExpressionType": "LambdaExpression",
    "Operator": "OrElse",
    "Rules": [
      {
        "RuleName": "IsBonusEligible",
        "ErrorMessage": "Error",
        "ErrorType": "Error",
        "RuleExpressionType": "LambdaExpression",
        "Expression": "input1.BonusAmount > 0 AND (input1.IsBonusEligible==\"true\" AND input1.BonusFrequency==input1.BonusCycle)",
        "Actions": {
          "OnSuccess": {
            "Name": "OutputExpression",
            "Context": {
              "Expression": "(input1.BonusAmount)"
            }
          }
        }
      },
      {
        "RuleName": "elseBonusEligible",
        "ErrorMessage": "Error",
        "ErrorType": "Error",
        "RuleExpressionType": "LambdaExpression",
        "Expression": "input1.BonusAmount == 0 AND input1.IsBonusEligible==\"false\" ",
        "Actions": {
          "OnSuccess": {
            "Name": "OutputExpression",
            "Context": {
              "Expression": "input1.FlatBonus"
            }
          }
        }
      }
    ]

  },
  {
    "RuleName": "PaymentAmountToClient",
    "SuccessEvent": "30",
    "ErrorMessage": "Error",
    "ErrorType": "Error",
    "RuleExpressionType": "LambdaExpression",
    "Expression": "input1.PaymentDueDate == input1.PaymentDate",
    "Actions": {
      "OnSuccess": {
        "Name": "OutputExpression", 
        "Context": { 
          "Expression": "input1.BalanceAmount + {BonusPayment} + {MinimumPayment}"
        }
      }
    }

  }
]

}
]

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

No repository files or tests are named. Start by reviewing the nested Rules JSON and the {BonusPayment} and {MinimumPayment} references, then determine the expected behavior for invoking named rules within another rule and how success outputs should be combined; done means the supported behavior is defined and covered by validation or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.