j-easy / easy-rules

The simple, stupid rules engine for Java
https://github.com/j-easy/easy-rules/wiki
MIT License
4.86k stars 1.05k forks source link

How to update facts in Action: #370

Open sss534534 opened 2 years ago

sss534534 commented 2 years ago

how to update facts in yml:

`name: "weather rule" description: "if it rains then take an umbrella" condition: "rain == true" actions:

[Error: unresolvable property or identifier: facts] [Near : {... facts.put("umbrella", true); ....}] ^ [Line: 1, Column: 1]

sss534534 commented 2 years ago

Just Same meaning as below:

``

    org.jeasy.rules.api.Rule weatherRule = new RuleBuilder()
            .name("weather rule")
            .description("if it rains then take an umbrella")
            .when(facts -> facts.get("rain").equals(true))
            .then(facts -> {
                System.out.println("It rains, take an umbrella!");
                facts.put("umbrella", true);
            })

``

chhil commented 2 years ago

See FAQ

https://github.com/j-easy/easy-rules/wiki/faqs#8-how-to-addassign-new-facts-in-rules-written-in-an-expression-language