Skip to content

Unable to retrieve facts in a loop #197

Description

@Hervinho

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions