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

Unable to retrieve facts in a loop #197

Open
Hervinho opened this issue Jul 26, 2016 · 1 comment
Open

Unable to retrieve facts in a loop #197

Hervinho opened this issue Jul 26, 2016 · 1 comment
Labels

Comments

@Hervinho
Copy link

Hervinho commented Jul 26, 2016

Hi! I am trying to retrieve facts in a for loop, coz Im sending differenct array objects to the rules, but when I retrieve, only the first object sent to the engine is retrieve. I dont know why. Here is my code:

for(var i = 0; i < rows.length; i++){
                            ev[i] = new Event(rows[i].id, rows[i].name, rows[i].code, rows[i].category_id, rows[i].inventory, rows[i].type,
                                rows[i].value, rows[i].total);
                                eventSentToRule = flow.getSession(ev[i]); //assert event
                                //Fire rules and retrieve facts

                                eventSentToRule.on("event", function (obj) { eve = obj.event;})
                                        .match().then(function (err) {
                                         if(err){
                                        console.error(err);
                                                res.redirect('/home');
                                    }else{
                                            if(eve){
                                                eventOutputFromNools[i] = eve;
                                                console.log("Type: " + eventOutputFromNools[i].type);
                                                //console.log(eve.type);
                                                eventSentToRule.dispose();
                                                res.redirect('/newsponsorship');
                                            }
                                        }
                                 });
                                 eventSentToRule.dispose();//this remains
                        }

And my nools rule engine is as follows:

rule TicketHospitalityTier2{
  when{
    e: Event e.code == "TICKETS_HOSPITALITY" && e.type == "T2";
  }
  then{
    var reach = e.inventory * 0.30;
    modify(e, function(){ this.total = reach * e.value;});
    this.emit("event", {event:e});
    this.assert({event:e});
    console.log("Category TICKETS_HOSPITALITY T2 - Total: " + e.total);
  }
}

So it seems like I can only get eventOutputFromNools[0]
Thanks for the help

@DevSide
Copy link
Collaborator

DevSide commented Oct 3, 2016

Where eventOutputFromNools is declared ?
Are you sure you can't accomplish this in another way ?
Keep in mind that you should not have too much logic out of your rules..

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

No branches or pull requests

2 participants