Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Referencing another Rule #263

Closed
damodaranr started this conversation in Ideas
May 24, 2021 · 2 comments · 2 replies
Discussion options

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.

You must be logged in to vote

Replies: 2 comments 2 replies

Comment options

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.

You must be logged in to vote
2 replies
Comment options

Can I get an example of how this can be achieved using a json construct please?

Comment options

Was thinking more on the lines of referencing the evaluation of a previously defined condition/event outcome in another rule so as to not restate the facts (Again idea being to having minimal js coding for the rules). See below example :
"decisions": [
{
"conditions": {
"any": [
{
"fact": "name",
"operator": "equal",
"value": "David"
},
{
"fact": "age",
"operator": "greaterThan",
"value": "21"
}
]
},
"event": {
"type": "DavidCanDrink",
}
},
{
"conditions": {
"all": [
{
"conditionRef": "DavidCanDrink",
"operator": "equal",
"value": "True"
},
{
"fact": "day",
"operator": "equal",
"value": "Monday"
}
]
},
"event": {
"type": "DavidMayDrink",
"params": {
"drinkName": "Martini"
}
}
}]

Comment options

@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.
I'm thinking you could even introduce a syntax similar to the { "fact": "name" } one used in the value field where you could reference a parameter. Something like: { "param": "name" } which would then require the new fact to have a name field in the params.

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"
 }
 } 
});
You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /