json-rules-engine icon indicating copy to clipboard operation
json-rules-engine copied to clipboard

Is it possible make value as a dynamic data like using path?

Open intermx-reddysai opened this issue 4 years ago • 3 comments

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'
    }
  }

intermx-reddysai avatar Jul 21 '21 07:07 intermx-reddysai

+1

SivaGanesh56 avatar Aug 16 '21 15:08 SivaGanesh56

+1

raghava9010 avatar Aug 23 '21 10:08 raghava9010

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'
});

mcacek avatar Oct 15 '21 14:10 mcacek