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

Question: manipulate arrays of objects

Open dma82 opened this issue 5 years ago • 0 comments

Hi,

Would it be possible to load examples with complex facts, e.g. object with nested array of objects? How would you manipulate them?

Example:

var fact = {
  "parentObject": {
        "id": "abc123",
        "items": [{
             {
                 "id": 1,
                 "parentId": "abc123",
                 "status": null
             },
             {
                 "id": 2,
                 "parentId": "def234",
                 "status": null
             },
            {
                 "id": 3,
                 "parentId": "abc123",
                 "status": null
            }
        }]
   }
}

Let's say now that I want to create a rule to change the status of all objects in "items" array where parentId = parentObject.id; how can I achieve this?

In Drools (Java) I was able to bind to the object with those conditions to a variable and then to manipulate it in the "then" part, after I loaded all objects into the working memory.

Is there any way to achieve the same result with this library? Is there a better way other than loading each individual object into the working memory?

Maybe I missed it, but I couldn't find any example.

Thank you.

dma82 avatar Jul 29 '20 12:07 dma82