Referencing another Rule #263
Replies: 2 comments 2 replies
-
| Unless I'm misunderstanding, I think you should be able to achieve this by assigning the condition to a variable and using that variable when creating each rule. | 
Beta Was this translation helpful? Give feedback.
-
| @CacheControl Would it make sense to allow the creation of "facts" that used the condition format something like: engine.addFact({
   "name": "DavidCanDrink",
   "conditions": {
       "all": [
         {
            "fact": "name",
            "operator":"equal",
            "value": "David"
          },
          {
            "fact": "age",
             "operator": "greaterThanInclusive",
             "value": 21
          }
       ]
   }
});
engine.addRule({
  "conditions": {
    "all": [
      {
        "fact": "DavidCanDrink",
        "operator": "equal",
        "value": true
       },
       {
         "fact": "day",
         "operator": "equal",
         "value": "Monday",
    ]
  },
  "event": {
     "type": "DavidMayDrink",
      "params": {
        "drinkName": "Martini"
      }
  } 
});This could allow Facts to be defined by users and loaded into the system at run-time. The requirement would be that the fact would have to be a boolean value. Rewriting the above rule you could do something like: engine.addFact({
   "name": "CanDrink",
   "conditions": {
       "all": [
         {
            "fact": "name",
            "operator":"equal",
            "value": { "param": "name" }
          },
          {
            "fact": "age",
             "operator": "greaterThanInclusive",
             "value": 21
          }
       ]
   }
});
engine.addRule({
  "conditions": {
    "all": [
      {
        "fact": "CanDrink",
        "operator": "equal",
        "value": true,
        "params": {
          "name": "David"
        }
       },
       {
         "fact": "day",
         "operator": "equal",
         "value": "Monday",
    ]
  },
  "event": {
     "type": "DavidMayDrink",
      "params": {
        "drinkName": "Martini"
      }
  } 
}); | 
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I don't see how we can reference an already created rule/decision in a new decision so that we are not recreating the decision from scratch.
It would be nice if a condition can reference a pre existing condition. Is this possible now or could this be added.
A fact could allow picking another condition (decision) and automatically the possible values are True or False as it would be a type boolean.
Beta Was this translation helpful? Give feedback.
All reactions