question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dynamic Rule Results

See original GitHub issue

Hi

Is it possible to construct dynamic rule result. For example could

event: { 
    type: 'honor-roll',
    params: {
      message: 'Student made the athletics honor-roll'
    }
  }

message parameter be constructed in the runtime?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
MattCopenhavercommented, Feb 5, 2020

@waglik I think what you’re describing is more of a Dynamic Event rather than a Dynamic Rule Result.

Accessing the almanac or factResult within onSuccess should do the trick. Your onSuccess function will have to contain the logic of how to build the dynamic events/results.

onSuccess: https://github.com/CacheControl/json-rules-engine/blob/master/docs/engine.md#engineonsuccess-functionobject-event-almanac-almanac-ruleresult-ruleresult Usage of Alamanc within an onSuccess: https://github.com/CacheControl/json-rules-engine/blob/master/docs/almanac.md#retrieve-fact-values-when-handling-events Rule Result (contains factResult): https://github.com/CacheControl/json-rules-engine/blob/master/docs/rules.md#rule-results

1reaction
CacheControlcommented, Dec 19, 2020

Can an event be decorated onSuccess like below without the added parameters getting permanently added to the rule?

Couple options here to avoid event mutation impacting other engine runs:

  1. You could have a data structure outside of the engine scope that tracks the state, e.g.:
let newEvent
engine.on('success', function(event, almanac, ruleResult) {
  newEvent = cloneDeep(event)
  newEvent.params.newProp1 = "decoration 1";
})
  1. if you’d prefer to keep things more internal to the engine itself, you could use almanac.addRuntimeFact() to save state and then retrieve it from the almanac later after run() completes:
engine.on('success', function(event, almanac, ruleResult) {
  newEvent = cloneDeep(event)
  newEvent.params.newProp1 = "decoration 1";
  almanac.addRuntimeFact('new-event', newEvent)
})
const {almanac} = engine.run();
await almanac.factValue('new-event')
Read more comments on GitHub >

github_iconTop Results From Across the Web

Create simpler and faster rules for dynamic groups - Azure AD
Simpler and more efficient rules result in better dynamic group processing times. When writing membership rules for dynamic groups, ...
Read more >
Default values and dynamic rules - Infowise
Dynamic rules allow you to set values to columns dynamically and automatically, based on static values, other column values, functions and expressions and ......
Read more >
Dynamic Rules - Spoofax
A dynamic rule definition is a regular (conditional) rewrite rule that is defined as part of a strategy rather than at top-level. The...
Read more >
Dynamic Rules - Product Manual - 2.X - Reblaze Portal
The Dynamic Rules section defines security rulesets that evaluate various criteria over time. · Note that Dynamic Rules do not block requests; they...
Read more >
Applying dynamic rule data managed in Excel to dataset
Applying dynamic rule data managed in Excel to dataset. Options ... When run, you get the results in the two output columns.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found