Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
intermx-reddysai opened this issue Jul 21, 2021 · 3 comments
Open

Comments

@intermx-reddysai
Copy link

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'
    }
  }
@SivaGanesh56
Copy link

+1

1 similar comment
@raghava9010
Copy link

+1

@mcacek
Copy link

mcacek commented Oct 15, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants