easy-rules icon indicating copy to clipboard operation
easy-rules copied to clipboard

Regarding list of Objects

Open baljatinder09 opened this issue 2 years ago • 6 comments

is there any way i can process list of objects. for eg emp[ { "name":"a", "dep":"xyz", "flage":true/false. ///// need to set based on dep in rule. }, { "name":"a", "dep":"abc", "flage":true/false. ///// need to set based on dep in rule. }, .... ..... }] like based on the dep.. i want rule should process each emp and set some flag in fact. is is possible with easy-rule. any eg will be help to understand it.

baljatinder09 avatar Apr 10 '22 06:04 baljatinder09

you should process rules on object which are in list one by one, I am assuming your requirement is to set flag for each object based on object's state.

dvgaba avatar Apr 10 '22 18:04 dvgaba

Yes , I want to process one by one. And action should set the Boolean flag ..is there any way I can do with rules ? Or I can use for each in conditions and are the flag and do nothing in action ?.... any other approach I can follow...

baljatinder09 avatar Apr 10 '22 20:04 baljatinder09

invoking rulesEngine.fire(rules, facts) in a for loop should work for you. Here fact should contain single object from your list

dvgaba avatar Apr 10 '22 23:04 dvgaba

Is there any way we can make it dynamic . I have list of rules .. for each rule then I can not reuse the engine code...

baljatinder09 avatar Apr 11 '22 13:04 baljatinder09

If you can share some sample rule and sample data might be able to help.

dvgaba avatar Apr 11 '22 13:04 dvgaba

Like this is my fact:- { "prac": { "contracts": [ { "net": "xyz", "selected":false },{ "net": "abc", "selected":false }, { "net": "abc2", "selected":false }, { "net": "abc3", "selected":false } ] } }

Rule:- [ { "name": "Business rule", "compositeRuleType": "ConditionalRuleGroup", "priority": 1, "composingRules":[ { "name": "Rule11", "description": "If net is xyz,abc3", "priority": 1, "condition": "contracts.net == "xyz" && contracts.net == "abc3"", "actions": [ "contracts.selected=true;" ] } ] } ] So i want the rule should process list of contracts and set the status selected=false as per the conditions the facts should list of contracts.

baljatinder09 avatar Apr 12 '22 01:04 baljatinder09