json-rules-engine
json-rules-engine copied to clipboard
Is it possible make value as a dynamic data like using path?
Example:
conditions: {
all: [{
fact: 'account-information',
operator: 'equal',
value: 'microsoft', // **Is it possible make this value 'microsoft' as a dynamic content?**
path: '$.company' // access the 'company' property of "account-information"
}]
},
event: {
type: 'microsoft-christmas-pto',
params: {
message: 'current microsoft employee taking christmas day off'
}
}
+1
+1
I believe that you can accomplish this by fact comparison and just provide the target value as dynamic fact at runtime or as a static fact on engine initialization.
https://github.com/CacheControl/json-rules-engine/blob/90272d61ed7bea8b7d4000305511e932490d2e2e/docs/rules.md#comparing-facts
Something along these lines. This doesn't address event message interpolation though as that's not currently supported.
const ptoRule = new Rule({
name: 'christmas-pto-rule',
conditions: {
all: [{
fact: 'account-information',
operator: 'equal',
value: {
fact: 'company'
},
path: '$.company'
}]
},
event: {
type: 'christmas-pto',
params: {
message: 'current employee taking christmas day off'
}
}
});
engine.addRule(ptoRule);
engine.run({
company: 'microsoft'
});